Results 1 to 13 of 13

Thread: [SOLVED] mainWidget()

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default [SOLVED] mainWidget()

    I'd like to do this below but don't work....w is null (000000):
    Qt Code:
    1. MainForm* w;
    2. w=(MainForm*) qApp->mainWidget()
    3. cout << w;
    To copy to clipboard, switch view to plain text mode 
    Why this?
    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: mainWidget()

    So you never set main widget for your app before
    a life without programming is like an empty bottle

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: mainWidget()

    Quote Originally Posted by zlatko
    So you never set main widget for your app before
    Or it's not type of MainWindow*..

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: mainWidget()

    Quote Originally Posted by jpn
    Or it's not type of MainWindow*..
    This would be true only in case of dynamic_cast<>.

  5. #5
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: mainWidget()

    the code above is in mywidget class;
    I set mainWidget in main.cpp:
    Qt Code:
    1. int main( int argc, char ** argv )
    2. {
    3. QApplication a( argc, argv );
    4.  
    5. MainForm w;
    6. w.resize(600,500);
    7. a.setMainWidget(&w);
    8. w.show();
    9. a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
    10. return a.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 
    Regards

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: mainWidget()

    Where do you invoke "qApp->mainWidget()"?

  7. #7
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: mainWidget()

    in mywidget.h (in constructor):

    Qt Code:
    1. MyWidget::MyWidget( QWidget *parent, const char *name)
    2. : QGLWidget ( parent, name, shareWidget )
    3. {
    4. setFormat(QGLFormat(DoubleBuffer | DepthBuffer));
    5. w=(MainForm*) qApp->mainWidget();
    6. }
    To copy to clipboard, switch view to plain text mode 
    Regards

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: mainWidget()

    Qt Code:
    1. MainForm w; // <-- here you invoke qApp->mainWidget()
    2. w.resize(600,500);
    3. a.setMainWidget(&w); // <-- and here you set the main widget
    To copy to clipboard, switch view to plain text mode 
    How do do you expect it to work?

    Edit: You can use "this", instead of qApp->mainWidget().

  9. #9
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: mainWidget()

    this? In constructor widget? I don't understand; this below don't compile.
    Qt Code:
    1. w=(MainForm*) this->mainWidget();
    To copy to clipboard, switch view to plain text mode 
    Do you say this?
    Regards

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: mainWidget()

    Quote Originally Posted by mickey
    Do you say this?
    I meant:
    Qt Code:
    1. w = this;
    To copy to clipboard, switch view to plain text mode 

    Edit: OK, I just noticed that you have MainForm and MyWidget. In this case you can probably use parent.

  11. #11
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: mainWidget()

    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:
    1. connect(this, SIGNAL(myUpdate()), w ,SLOT(updateWidgets()) );
    To copy to clipboard, switch view to plain text mode 
    Regards

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: mainWidget()

    Quote Originally Posted by mickey
    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.

  13. #13
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: mainWidget() SOLVED

    This don't work:
    Quote Originally Posted by jacek
    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:
    Qt Code:
    1. w= (MainForm*)this->topLevelWidget();
    To copy to clipboard, switch view to plain text mode 
    Thanks for help!
    Regards

Similar Threads

  1. [SOLVED] DirectShow Video Player Inside Qt
    By ToddAtWSU in forum Qt Programming
    Replies: 16
    Last Post: 3rd November 2011, 07:47
  2. Replies: 1
    Last Post: 18th August 2008, 22:22
  3. [SOLVED] subclassing qlabel
    By mickey in forum Newbie
    Replies: 10
    Last Post: 4th June 2008, 14:43
  4. QPushButton, Icon right of text [solved]
    By Mike in forum Qt Programming
    Replies: 5
    Last Post: 31st January 2008, 20:53
  5. Replies: 1
    Last Post: 18th March 2006, 16:37

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.