PDA

View Full Version : how to show and hide frames?



rambo83
6th January 2010, 09:02
Hello,

I would like to present a popup at the beginning of my program, which let the user chose between 2 modes.
If the user makes his choice, then a new window shall be opened. Unfortunately, bot the popup and another window disappear after clicking on one of the pushbuttons. Can you tell me what is the reason and how to deal with this problem (see my code below)?
Thank you

best regards,

Vitali


#include <QApplication>
#include <QPushButton>
#include <QMessageBox>
#include <mainframe.h>
#include "dialog_start.h"
#include "OscillationGRN.h"

int main(int argc, char **argv)
{

QApplication app(argc, argv);

// first appears a popup, which will offer to the user 2 different kinds of problems
QMessageBox msgBox;
QPushButton *OscillationButton = msgBox.addButton("Sustained Oscillation", QMessageBox::ActionRole);
QPushButton *BenchmarkButton = msgBox.addButton("constrained Problems",QMessageBox::ActionRole);

msgBox.exec();

if(msgBox.clickedButton() == BenchmarkButton){ // if the user decide to cope with optimization of constrained benchmark problems

mainFrame mainWind;

// execute the initialization dialog
dialogStart start(0, &mainWind);
start.show(); // the mainWindow will be opened after the user click on START button within dialogStart
msgBox.hide();
}
else if(msgBox.clickedButton() == OscillationButton){ // if the user decide to cope with generation of oscillation by means of Gene Regulatory Networks
OscillationGRN evoGRN;
evoGRN.show();
msgBox.hide();
}
return app.exec();

exit(EXIT_SUCCESS);

}

aamer4yu
6th January 2010, 09:35
Probably because you are declaring the windows inside the if else condition.

mainFrame mainWind; and OscillationGRN evoGRN;
Try declaring them above the if condition on a larger scope :)

rambo83
6th January 2010, 09:53
Yes, you are right, aamer4yu. Thank you

Now it works with the following code:


#include <QApplication>
#include <QPushButton>
#include <QMessageBox>
#include <mainframe.h>
#include "dialog_start.h"
#include "OscillationGRN.h"
#include <iostream>

int main(int argc, char **argv)
{

QApplication app(argc, argv);

// first appears a popup, which will offer to the user 2 different kinds of problems
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Question);
msgBox.setText("Which one of the optimization problems do you want to execute?");
msgBox.setInformativeText("Make your choice by clicking on button.");
QPushButton *OscillationButton = msgBox.addButton("Sustained Oscillation", QMessageBox::ActionRole);
QPushButton *BenchmarkButton = msgBox.addButton("Constrained Problems",QMessageBox::NoRole);

msgBox.exec();

mainFrame mainWind; // build Main Window

dialogStart start(0, &mainWind); // build Initialization window

OscillationGRN evoGRN; // build OscillationGRN window

if(msgBox.clickedButton() == BenchmarkButton){ // if the user decide to cope with optimization of constrained benchmark problems

start.show(); // the mainWindow will be opened after the user click on START button within dialogStart

}
else if(msgBox.clickedButton() == OscillationButton){ // if the user decide to cope with generation of oscillation by means of Gene Regulatory Networks

evoGRN.show();

}
return app.exec();

exit(EXIT_SUCCESS);

}