fredcrs
fredcrs

Reputation: 3621

Qt opening another window when first one has closed

I´ve beeing programming Java for some time right now...Now that I got into C++ and Qt I am a bit lost about GUI Thread (EDT Thread) and Worker Thread I am trying to make the main window of my application open only when the configuration window is closed. I dont want to put the code for creating the main window in the OK button of my configuration window. I tryed to make them modal but the main window still opens..... Afther configuration is complete I still have to see if there is an application update...So its something like

EDIT: This is my main:

ConfigurationWindow *cw = new ConfigurationWindow();
//if there is no text file - configuration
cw->show();

//**I need to stop here until user fills the configuration

MainWindow *mw = new MainWindow();
ApplicationUpdateThread *t = new ApplicationUpdateThread();
//connect app update thread with main window and starts it
mw->show();

Upvotes: 0

Views: 2226

Answers (3)

Manjabes
Manjabes

Reputation: 1904

If your ConfigurationWindow is a QDialog, you could connect the finished(int) signal to the MainWindow's show() slot (and omit the show() call from main).

Upvotes: 1

hmuelner
hmuelner

Reputation: 8221

You have to learn about signals and slots. The basic idea is that you would send a signal when you configuration is finished. You put your QMainWindow in a member variable and call mw->show() in a slot of your main programm that is connected with the configurationFinished signal.

Upvotes: 3

Anthony
Anthony

Reputation: 8788

Try something like this:

#include <QtGui>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QDialog *dialog = new QDialog;
    QSlider *slider = new QSlider(dialog);
    QHBoxLayout *layout = new QHBoxLayout(dialog);
    layout->addWidget(slider);
    dialog->setLayout(layout);
    dialog->exec();
    qDebug() << slider->value(); // prints the slider's value when dialog is closed

    QMainWindow mw; // in your version this could be MainWindow mw(slider->value());
    w.show();

    return a.exec();
}

The idea is that your main window's constructor could accept parameters from the QDialog. In this contrived example I'm just using qDebug() to print the value of the slider in the QDialog when it's closed, not passing it as a parameter, but you get the point.

EDIT: You might also want to "delete" the dialog before creating the main window in order to save memory. In that case you would need to store the parameters for the main window constructor as separate variables before deleting the dialog.

Upvotes: 3

Related Questions