PDA

View Full Version : dialog still in topLevelWidgets() after been closed



peter a
16th September 2010, 23:00
Hi I`m a very much a newbie to Qt , So learning the basics of QT .
( with Qt creator 2 for a mini2440 embedded linux)

My problem !!! , I`ve made a set of pustbuttons open a set of dialog windows with :-

void myQtApp::Log_in_clicked()
{
Password * My_dialog = new Password;
My_dialog->setWindowFlags(Qt::FramelessWindowHint );
My_dialog->move(0,0);
My_dialog->exec();
//delete My_dialog;
}

The dialog above windows is an “Enter your password blocking screen”
If I close the box all looks o.k,. it vanishes from the screen and can reopen it again.

Another dialog window runs this :-

foreach (QWidget *widget, QApplication::topLevelWidgets())
{
test = widget->windowTitle();
ui->list->append(test);
} // test is a QString and list a textedit box

PROBLEM !! , I get the log in screen title appearing all the times I have run it .
So it`s not been cleared has a toplevelwidget even though the window as been closed.
The only way I`ve found to stop this is with the delete My_dialog; bit added .

Thank in advance peter

wysota
16th September 2010, 23:20
The window is closed but it is still there and it is still top-level. Either delete it or filter out windows that are not visible (QWidget::visible).

peter a
17th September 2010, 00:05
O.k , so if I have this right , closing a windows does not delete it is a top level widget , it just deletes it from the display ? , so instead of making a new window each time, should I just reopen the same one ?

wysota
17th September 2010, 00:25
It doesn't delete anything. It just hides the window. Yes, you can reopen it at any time.

peter a
17th September 2010, 01:24
o.k , Thanks !!!

I`ve found have to delete it now with :- My_dialog->setAttribute(Qt::WA_DeleteOnClose);

So what is the right way to reopen a window ? , I can find any handles to save and use again ..

The only way I can think of is to look at the top level widgets until I see the right windows title or other marker, then open it.

ChrisW67
17th September 2010, 06:52
In this bit of code:


void myQtApp::Log_in_clicked()
{
Password * My_dialog = new Password;
My_dialog->setWindowFlags(Qt::FramelessWindowHint );
My_dialog->move(0,0);
My_dialog->exec();
}

You create the dialog object on the heap and then allow the local variable that you stored the pointer in to go out of scope. If you put that address into a member variable instead you could access that object from other places in the code (to call exec(), show() or delete the object).

peter a
17th September 2010, 08:15
Thanks , at this time that makes no sense to me right now , but you have given me some good key word to work it out.

NEWBIE !!!! Any chance of giving me a example to work off Please