PDA

View Full Version : Show Widget B if an event in Widget A occurred ?



nackasha
2nd August 2011, 20:54
Hello Folks,

I have Widgets A and B. Lets say Widget A has a push button to assign x1=true, while it is initially is initialized to false.

What i want to do is show Widget A, then after pressing the push button Widget A hides and Widget B appears.

I 'think' I am not really understanding the loop event sequence. My code is as the following:




#include <QtGui/QApplication>
#include "mainwindow.h"
#include "startupscreen.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);

StartUpScreen startup;
startup.show();

if (startup.x1)
{
MainWindow w;
w.show();
startup.hide();
}
return a.exec();
}


Thank you very much,

NullPointer
2nd August 2011, 21:05
Why you don't open the MainWindow inside the pushbutton event?
Something like:


MainWindow * w = new MainWindow(0); // in the constructor, paarent should be zero, so we can delete StartUpScreen without problems.
w->show();
deleteLater();


Hth.

stampede
2nd August 2011, 21:05
w goes out of scope, so you don't have a chance to see it.
---
sorry, actually I paid more attention to the code rather than your question :o
You should wait and react on the push button click, because this

startup.show();

if (startup.x1)
...
does not give the main event loop a chance to start before you check the variable.
Instead of assigning a variable, create and show the second window.

NullPointer
2nd August 2011, 21:15
I don't think so...

StartUpScreen will appear just when we enter the "a.exec()", which is after the validation of x1....