Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt best way to invoke methods of QMainWindow from other widget

Qt best way to invoke methods of QMainWindow from other widget

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 3.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    umen242
    wrote on last edited by
    #1

    I have main window from type QMainWindow, then I set some widget and give this widget the QMainWindow as parent in its constructor , the QMainWindow passed as Object. now I need from this widget invoke method from the QMainWindow. what will be the best way to do it ?

    this is how the widget looks like:

    @DataListModel::DataListModel( QObject *parent ) :
    QStandardItemModel( 0, 0, parent )

    {
    // here I like to invoke some QMainWindow method?
    //can I cast somehow the parent ? or use some pointer ?

    }
    @

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      @
      QMainWindow mainWindow = qobject_cast<QMainWindow>(parent());
      if(mainWindow != 0)
      {
      ...
      }
      @

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #3

        Or if you always pass a QMainWindow as parent, change the constructor to take only QMainWindow pointers as parent and save the parent in a class attribute.

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved