View Full Version : [SOLVED] mainWidget()
mickey
23rd February 2006, 10:47
I'd like to do this below but don't work....w is null (000000):
MainForm* w;
w=(MainForm*) qApp->mainWidget()
cout << w;
Why this?
zlatko
23rd February 2006, 11:06
So you never set main widget for your app before:)
jpn
23rd February 2006, 11:08
So you never set main widget for your app before:)
Or it's not type of MainWindow*..
jacek
23rd February 2006, 11:23
Or it's not type of MainWindow*..
This would be true only in case of dynamic_cast<>.
mickey
23rd February 2006, 12:26
the code above is in mywidget class;
I set mainWidget in main.cpp:
int main( int argc, char ** argv )
{
QApplication a( argc, argv );
MainForm w;
w.resize(600,500);
a.setMainWidget(&w);
w.show();
a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
return a.exec();
}
jacek
23rd February 2006, 13:36
Where do you invoke "qApp->mainWidget()"?
mickey
23rd February 2006, 16:37
in mywidget.h (in constructor):
MyWidget::MyWidget( QWidget *parent, const char *name)
: QGLWidget ( parent, name, shareWidget )
{
setFormat(QGLFormat(DoubleBuffer | DepthBuffer));
w=(MainForm*) qApp->mainWidget();
}
jacek
23rd February 2006, 16:41
MainForm w; // <-- here you invoke qApp->mainWidget()
w.resize(600,500);
a.setMainWidget(&w); // <-- and here you set the main widget
How do do you expect it to work?
Edit: You can use "this", instead of qApp->mainWidget().
mickey
23rd February 2006, 17:16
this? In constructor widget? I don't understand; this below don't compile.
w=(MainForm*) this->mainWidget();
Do you say this?
jacek
23rd February 2006, 17:19
Do you say this?
I meant:
w = this;
Edit: OK, I just noticed that you have MainForm and MyWidget. In this case you can probably use parent.
mickey
23rd February 2006, 17:26
It compile but Bug error occurs....
Furthermore I must code this below.....and sender and receiver are the same and don't work connect....
connect(this, SIGNAL(myUpdate()), w ,SLOT(updateWidgets()) );
jacek
23rd February 2006, 17:29
It compile but Bug error occurs....
Furthermore I must code this below.....and sender and receiver are the same and don't work connect....
Then try "w = parent" if the main window is the parent of your widget.
mickey
23rd February 2006, 17:39
This don't work:
Then try "w = parent" if the main window is the parent of your widget.
( console says "parent" isn't the correct receiver() for my connect)
This works:
w= (MainForm*)this->topLevelWidget();
Thanks for help!
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.