Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 3

Qt-interest Archive, December 2007
non-modal child window


Message 1 in thread

Hi!

I want to create new non-modal windows which will be closed if the main 
window is closed. I tried various settings of QDialog and QWidget but 
had no luck - either the new windows is modal or the new window stays 
open although the main window was already closed.

Is it possible to create a new non-modal QWidget/QDialog which will 
automatically closed when the main window is closed? How?

thanks
Klaus

--
 [ signature omitted ] 

Message 2 in thread

On 12/18/07, Klaus Darilion <klaus.mailinglists@xxxxxxxxx> wrote:
> Is it possible to create a new non-modal QWidget/QDialog which will
> automatically closed when the main window is closed? How?

This is one way:

QWidget *parent = new QWidget();
QWidget *child = new QWidget();

connect( parent, SIGNAL(destroyed(QObject *)), child, SLOT(close());

Cheers

Rich.

--
 [ signature omitted ] 

Message 3 in thread


Richard Moore schrieb:
> On 12/18/07, Klaus Darilion <klaus.mailinglists@xxxxxxxxx> wrote:
>> Is it possible to create a new non-modal QWidget/QDialog which will
>> automatically closed when the main window is closed? How?
> 
> This is one way:
> 
> QWidget *parent = new QWidget();
> QWidget *child = new QWidget();
> 
> connect( parent, SIGNAL(destroyed(QObject *)), child, SLOT(close());


Hi Richard!

This still does not work for me. I have a main windows with a QWidget. 
Further I open a non-modal Dialog (using show() instead of exec()).

If I close the main window by pressing the "X" (right upper corner) the 
main windows disappears, but the dialog window is still open.

I think this is because the "destroyed" signal is not sent. I tried to 
set setAttribute(Qt::WA_DeleteOnClose); for the main windows, but now my 
application crashes if I close the main windows.

Any hints?

thanks
klaus

--
 [ signature omitted ] 

Message 4 in thread

On 18.12.07 17:07:21, Klaus Darilion wrote:
>
>
> Richard Moore schrieb:
>> On 12/18/07, Klaus Darilion <klaus.mailinglists@xxxxxxxxx> wrote:
>>> Is it possible to create a new non-modal QWidget/QDialog which will
>>> automatically closed when the main window is closed? How?
>>
>> This is one way:
>>
>> QWidget *parent = new QWidget();
>> QWidget *child = new QWidget();
>>
>> connect( parent, SIGNAL(destroyed(QObject *)), child, SLOT(close());
>
>
> Hi Richard!
>
> This still does not work for me. I have a main windows with a QWidget. 
> Further I open a non-modal Dialog (using show() instead of exec()).
>
> If I close the main window by pressing the "X" (right upper corner) the 
> main windows disappears, but the dialog window is still open.
>
> I think this is because the "destroyed" signal is not sent. I tried to set 
> setAttribute(Qt::WA_DeleteOnClose); for the main windows, but now my 
> application crashes if I close the main windows.

Find out why it crashes. I suspect you're accessing the mainwindow from
the dialog or you access something from the mainwindow destructor that
doesn't exist anymore. 

Note: the destroyed signal is sent after your own destructor has
finished, its called just before deleting the data of the underlying
QObject part of your instance.

Andreas

-- 
 [ signature omitted ] 

Message 5 in thread

On Tuesday 18 December 2007 17:07:21 Klaus Darilion wrote:
> Richard Moore schrieb:
> > On 12/18/07, Klaus Darilion <klaus.mailinglists@xxxxxxxxx> wrote:
> >> Is it possible to create a new non-modal QWidget/QDialog which will
> >> automatically closed when the main window is closed? How?
<SNIP/>
Of course it may be a bit old fashioned like, but you could simply store the 
pointer to the dialog in the MainWindow and delete it in its destructor.
Usually works for me.

--
 [ signature omitted ] 

Message 6 in thread

> On Tuesday 18 December 2007 17:07:21 Klaus Darilion wrote:
>> Richard Moore schrieb:
>> > On 12/18/07, Klaus Darilion <klaus.mailinglists@xxxxxxxxx> wrote:
>> >> Is it possible to create a new non-modal QWidget/QDialog which will
>> >> automatically closed when the main window is closed? How?
> <SNIP/>
> Of course it may be a bit old fashioned like, but you could simply store
> the
> pointer to the dialog in the MainWindow and delete it in its destructor.
> Usually works for me.

I now solved it the following way:

void MainWindow::closeEvent(QCloseEvent *event) {
	if (reallyExit()) {
		writeSettings();
		shutdownSipStack();
		parentWindow->close();
		parentWindow=0;
		event->accept();
	} else {
		event->ignore();
	}
}

thanks to all
Klaus

--
 [ signature omitted ]