I have a Qdialog in which i get some inputs to use on my mainwindow. so it must appear first than mainwindow.
the problem is that my mainwindow does not show up. here's my main.cpp
#include <QtGui/QApplication>
#include "planevolume.h"
#include "dialog.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Dialog *dialog= new Dialog;
dialog->show();
planevolume mainwindow;
bool dialogcheck = dialog->isHidden();
if (dialogcheck==1)
{
mainwindow.show();
}
else
{
}
return app.exec();
}
I have a pushbutton that when pressed hides the qdialog and if it is hidden than the mainwindow should show up, right?
here's the SLOT i used:
void Dialog::startplanevolume()
{
if (xMax==0 || yMax==0 || zMax==0 || xMMax==0 || yMMax==0 || zMMax==0)
{
ui->label_17->setText("Error: Can't start, invalid measures");
}
else
{
hide();
}
}
the mainwindow can only start after that button is clicked as only then I have the inputs to the main winodw
When you press the button, you call your
Dialog::startplanevolume
, yes, but that's it. You don't go back to the main loop.If you want to display your
mainwindow
, you may want to call aplanevolume.show()
in yourDialog::startplanevolume
, just after thehide
.It might be tricky if your objects are in different files, though. So maybe you could define a signal like
DialogChecked
, emit this signal in yourDialog::startplanevolume
(after thehide
, of course...), and modify yourmain
so that it would callmainwindow.setVisible(1)
when receiving aDialogChecked
.So the problem here is that calling dialog->show() does not block execution. The minute that call is made, it moves on to the next method. You need to block execution until the user finishes putting input in.
Make your main like this:
And in your dialog class, make your method look like:
The
PushButton
action may happen only afterapp.exec()
is called. It makes no sense testing dialog properties before the main loop is entered.The expected behavior may be reached by setting up the components to start sequentially in an asynchronous way. In Qt world, this means using signals and slots.