Results 1 to 3 of 3

Thread: Cant get QMainWindow().centralwidget....

  1. #1
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Cant get QMainWindow().centralwidget....

    QMainWindow().centralWidget() always gives me zero ....
    I need to access to this widget from any point on my app...
    What I'm doing bad ? Thanks.

  2. #2
    Join Date
    Oct 2007
    Location
    Lake Forest, CA, USA
    Posts
    132
    Thanks
    10
    Thanked 27 Times in 22 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: Cant get QMainWindow().centralwidget....

    You getting central widget of new QMainWidget instance, obviously it is empty. Call centralWidget() of your QMainWidget subclass (often it's called MainWidget). To access something through all application you can use, for example, singleton.
    Oleg Shparber

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Cant get QMainWindow().centralwidget....

    Quote Originally Posted by tonnot View Post
    QMainWindow().centralWidget() always gives me zero ....
    As Oleg says, the central widget of a default constructed QMainWindow is not likely to be useful. Further, you seem to be expecting QMainWindow::centralWidget() to be static: it isn't and cannot reasonably be so.
    I need to access to this widget from any point on my app...
    Provide public functions that provide the interface for external entities to operate on the private UI widgets of the main window. Generally these functions will provide a controlled way to achieve some higher level abstract effect and not a mechanism to violate encapsulation.
    What I'm doing bad ? Thanks.
    Probably perpetuating a bad design.

Similar Threads

  1. QSrollArea as centralwidget of QMainWindow
    By dpatel in forum Qt Programming
    Replies: 1
    Last Post: 7th June 2011, 12:07
  2. QtDesigner: set centralWidget of QMainWindow
    By Florianx in forum Newbie
    Replies: 1
    Last Post: 25th June 2010, 18:17
  3. QMainWindow/centralWidget question
    By graciano in forum Qt Programming
    Replies: 6
    Last Post: 15th April 2010, 22:49
  4. QMainWindow -> centralWidget size
    By lalesculiviu in forum Qt Programming
    Replies: 2
    Last Post: 25th October 2009, 09:40
  5. QMainWindow->centralWidget with alpha?
    By wafto in forum Newbie
    Replies: 2
    Last Post: 7th December 2008, 02:52

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.