Results 1 to 4 of 4

Thread: QDialog::show() not displaying child

  1. #1
    Join Date
    Aug 2010
    Posts
    65
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default QDialog::show() not displaying child

    I've just started tinkering with QDialog and so just wanted to create one with a button saying "OK" there. The code's the following:

    Qt Code:
    1. bool MyCanvas::HorizonDialog()
    2. {
    3. QDialog* dlg = new QDialog(this);
    4. dlg->setAttribute(Qt::WA_DeleteOnClose);
    5. QHBoxLayout layout;
    6. QPushButton ok("OK",dlg);
    7. ok.setDefault(true);
    8. connect(&ok,SIGNAL(clicked()),dlg,SLOT(close()));
    9. layout.addWidget(&ok);
    10. dlg->setLayout(&layout);
    11. dlg->raise();
    12. dlg->show();
    13. return true;
    14. }
    To copy to clipboard, switch view to plain text mode 

    I want the dialog to be modeless, so I chose to use QDialog::show() instead of ::exec(). However, when I run the program, the pushbutton doesn't appear. Should I use QDialog::exec(), however, the button does appear and everything works fine. I've tried "ok.show()" both before and after "dlg->show()" and neither worked.

    Help?

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QDialog::show() not displaying child

    Here comes the good old standard C++ error: Create the layout on the heap, not on the stack. (Use new!)

  3. #3
    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: QDialog::show() not displaying child

    ... and the button too.
    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.


  4. #4
    Join Date
    Aug 2010
    Posts
    65
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QDialog::show() not displaying child

    I hate myself.

Similar Threads

  1. Replies: 4
    Last Post: 4th January 2009, 01:14
  2. Qt::WA_DeleteOnClose while a child QDialog is executed
    By nooky59 in forum Qt Programming
    Replies: 4
    Last Post: 11th July 2008, 12:45
  3. QMainWindow child of a QDialog
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 16th January 2008, 07:16
  4. 100% CPU load after displaying a QDialog...
    By hickscorp in forum Qt Programming
    Replies: 1
    Last Post: 3rd April 2007, 02:10
  5. Qdialog as a child widget
    By dave in forum Newbie
    Replies: 12
    Last Post: 14th November 2006, 09:43

Tags for this Thread

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.