I'd like to do this below but don't work....w is null (000000):
Why this?Qt Code:
MainForm* w; w=(MainForm*) qApp->mainWidget() cout << w;To copy to clipboard, switch view to plain text mode
I'd like to do this below but don't work....w is null (000000):
Why this?Qt Code:
MainForm* w; w=(MainForm*) qApp->mainWidget() cout << w;To copy to clipboard, switch view to plain text mode
Regards
So you never set main widget for your app before
a life without programming is like an empty bottle
Or it's not type of MainWindow*..Originally Posted by zlatko
This would be true only in case of dynamic_cast<>.Originally Posted by jpn
the code above is in mywidget class;
I set mainWidget in main.cpp:
Qt 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(); }To copy to clipboard, switch view to plain text mode
Regards
Where do you invoke "qApp->mainWidget()"?
in mywidget.h (in constructor):
Qt Code:
{ w=(MainForm*) qApp->mainWidget(); }To copy to clipboard, switch view to plain text mode
Regards
How do do you expect it to work?Qt Code:
MainForm w; // <-- here you invoke qApp->mainWidget() w.resize(600,500); a.setMainWidget(&w); // <-- and here you set the main widgetTo copy to clipboard, switch view to plain text mode
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?Qt Code:
w=(MainForm*) this->mainWidget();To copy to clipboard, switch view to plain text mode
Regards
I meant:Originally Posted by mickey
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....
Qt Code:
connect(this, SIGNAL(myUpdate()), w ,SLOT(updateWidgets()) );To copy to clipboard, switch view to plain text mode
Regards
Then try "w = parent" if the main window is the parent of your widget.Originally Posted by mickey
This don't work:
( console says "parent" isn't the correct receiver() for my connect)Originally Posted by jacek
This works:
Thanks for help!Qt Code:
w= (MainForm*)this->topLevelWidget();To copy to clipboard, switch view to plain text mode
Regards
Bookmarks