PDA

View Full Version : QDialog::show() not displaying child



Wasabi
13th September 2010, 16:15
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:


bool MyCanvas::HorizonDialog()
{
QDialog* dlg = new QDialog(this);
dlg->setAttribute(Qt::WA_DeleteOnClose);
QHBoxLayout layout;
QPushButton ok("OK",dlg);
ok.setDefault(true);
connect(&ok,SIGNAL(clicked()),dlg,SLOT(close()));
layout.addWidget(&ok);
dlg->setLayout(&layout);
dlg->raise();
dlg->show();
return true;
}

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?

Lykurg
13th September 2010, 16:22
Here comes the good old standard C++ error: Create the layout on the heap, not on the stack. (Use new!)

wysota
13th September 2010, 16:51
... and the button too.

Wasabi
14th September 2010, 01:38
I hate myself.