hakermania
3rd July 2011, 20:25
Hello developers!
My application is both console and GUI, depending on the arguments it takes.
So, the code is as follows:
#include.....
//..
class EarthTimer (bla bla, making a subclass of QTimer....
..
//here we connect the timer with the timers_slot() function
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
EarthTimer earthtimer;
earthtimer.start(1800000); //30 min
return a.exec(); //we have started the timer but we have to call this otherwise the application will immediately close
}
void timers_slot(){
//doing some specific job
..//code
..
..
if(something_is_true){
MainWindow w;
w.show();
/*here I am trying to start the GUI, what it does is to go through the constructor
of the MainWindow class and then exits, without showing the GUI, I guess I have
to call return a.exec() again, but a is not declared here and cannot be global :(*/
}
}
Ι think the comments are pretty specific, but if someone didn't get it:
I call return a.exec() after starting the timer so as to avoid program's quit, and then if something is true in the timers_slot() I am trying to open the GUI. It goes through the constructor of the GUI but it does not show anything. I assume I have to call return a.exec() again there but it is declared in main() function and cannot be global.
May I create another QApplication and return it there?
My application is both console and GUI, depending on the arguments it takes.
So, the code is as follows:
#include.....
//..
class EarthTimer (bla bla, making a subclass of QTimer....
..
//here we connect the timer with the timers_slot() function
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
EarthTimer earthtimer;
earthtimer.start(1800000); //30 min
return a.exec(); //we have started the timer but we have to call this otherwise the application will immediately close
}
void timers_slot(){
//doing some specific job
..//code
..
..
if(something_is_true){
MainWindow w;
w.show();
/*here I am trying to start the GUI, what it does is to go through the constructor
of the MainWindow class and then exits, without showing the GUI, I guess I have
to call return a.exec() again, but a is not declared here and cannot be global :(*/
}
}
Ι think the comments are pretty specific, but if someone didn't get it:
I call return a.exec() after starting the timer so as to avoid program's quit, and then if something is true in the timers_slot() I am trying to open the GUI. It goes through the constructor of the GUI but it does not show anything. I assume I have to call return a.exec() again there but it is declared in main() function and cannot be global.
May I create another QApplication and return it there?