Results 1 to 7 of 7

Thread: dialog still in topLevelWidgets() after been closed

  1. #1
    Join Date
    Sep 2010
    Posts
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default dialog still in topLevelWidgets() after been closed

    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
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: dialog still in topLevelWidgets() after been closed

    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).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Sep 2010
    Posts
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: dialog still in topLevelWidgets() after been closed

    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 ?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: dialog still in topLevelWidgets() after been closed

    It doesn't delete anything. It just hides the window. Yes, you can reopen it at any time.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Sep 2010
    Posts
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: dialog still in topLevelWidgets() after been closed

    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.

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: dialog still in topLevelWidgets() after been closed

    In this bit of code:
    Qt Code:
    1. void myQtApp::Log_in_clicked()
    2. {
    3. Password * My_dialog = new Password;
    4. My_dialog->setWindowFlags(Qt::FramelessWindowHint );
    5. My_dialog->move(0,0);
    6. My_dialog->exec();
    7. }
    To copy to clipboard, switch view to plain text mode 
    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).

  7. #7
    Join Date
    Sep 2010
    Posts
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: dialog still in topLevelWidgets() after been closed

    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
    Last edited by peter a; 17th September 2010 at 12:49.

Similar Threads

  1. Qt 4.2.2 static - *CLOSED*
    By maxpower in forum Qt Programming
    Replies: 1
    Last Post: 19th January 2007, 08:08
  2. modeless dialog closed signal?
    By gfunk in forum Qt Programming
    Replies: 2
    Last Post: 5th January 2007, 00:40
  3. Replies: 3
    Last Post: 23rd July 2006, 18:02
  4. QDomDocument - closed nodes?
    By naresh in forum Qt Programming
    Replies: 2
    Last Post: 19th April 2006, 08:10
  5. delete sub windows when they are closed?
    By Dark_Tower in forum Newbie
    Replies: 3
    Last Post: 21st March 2006, 18:50

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.