I'd like to do this below but don't work....w is null (000000):
Why this?Code:
MainForm* w; w=(MainForm*) qApp->mainWidget() cout << w;
Printable View
I'd like to do this below but don't work....w is null (000000):
Why this?Code:
MainForm* w; w=(MainForm*) qApp->mainWidget() cout << w;
So you never set main widget for your app before:)
Or it's not type of MainWindow*..Quote:
Originally Posted by zlatko
This would be true only in case of dynamic_cast<>.Quote:
Originally Posted by jpn
the code above is in mywidget class;
I set mainWidget in main.cpp:
Code:
int main( int argc, char ** argv ) { MainForm w; w.resize(600,500); a.setMainWidget(&w); w.show(); a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) ); return a.exec(); }
Where do you invoke "qApp->mainWidget()"?
How do do you expect it to work?Code:
MainForm w; // <-- here you invoke qApp->mainWidget() w.resize(600,500); a.setMainWidget(&w); // <-- and here you set the main widget
Edit: You can use "this", instead of qApp->mainWidget().
this? In constructor widget? I don't understand; this below don't compile.
Do you say this?Code:
w=(MainForm*) this->mainWidget();
I meant:Quote:
Originally Posted by mickey
Code:
w = this;
Edit: OK, I just noticed that you have MainForm and MyWidget. In this case you can probably use parent.
It compile but Bug error occurs....
Furthermore I must code this below.....and sender and receiver are the same and don't work connect....
Code:
connect(this, SIGNAL(myUpdate()), w ,SLOT(updateWidgets()) );
Then try "w = parent" if the main window is the parent of your widget.Quote:
Originally Posted by mickey
This don't work:
( console says "parent" isn't the correct receiver() for my connect)Quote:
Originally Posted by jacek
This works:
Thanks for help!Code:
w= (MainForm*)this->topLevelWidget();