This seems like a simple task, but I haven't been able to figure out how I would do it. I have two windows designed in Qt Creator, one of which is meant to open when a button is pressed in my main window. Here is the code I am trying to use to open it:
void MainWindow::on_generateDomain_clicked()
{
DomainGeneration dg;
dg.show();
}
DomainGeneration is the name of my window's class. The header and source code for this have not been altered from the default Qt Creator generated for me. Am I doing something wrong? I don't get any errors, the window just doesn't open when the button is pressed.
Connect your button signal clicked() with exec() slot of your popup window: connect(pushButton, SIGNAL(clicked()), popupWindow, SLOT(exec())); Where pushButton - pointer to your button, and popupWindow - pointer to your popup window. You can write this code in QMainWindow constructor.
{
DomainGeneration dg; // <-- automatic object
dg.show(); // equivalent to setVisible(true)
} // at this point dg is destroyed!
One solution is to make dg
a (private) data member of the MainWindow
class.
QDialog
has open()
and exec()
methods which show the dialog as a modal dialog. Probably you assumed that it was the default behavior. In your case though, dg
gets created and destroyed immediately.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With