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. Accessing mainwindow from another class

Accessing mainwindow from another class

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 522 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.
  • T Offline
    T Offline
    tiegert
    wrote on last edited by
    #1

    Hello guy's,

    i have tried to include the mainwindow header to another class, lets call that class A, and from that class A then add a dock to the main window.

    The problem is, that mainwindow already uses class A and has its header file included. So i get a circular dependency.

    If i use forward declaration in class A and type "class MainWindow;" i can not really use any functions of the main window class in class A.

    Is there someone with the same problem, or does someone have a solution on how to access the mainwindow class without a circular dependency?

    Thanks a lot
    Michael

    JonBJ 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #4

      Hi,

      If you want to communicate with your main window, use signals and slots.

      The fact that you start to have circular dependencies of that kind in a GUI application hints at an architectural issue.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      T 1 Reply Last reply
      1
      • T tiegert

        Hello guy's,

        i have tried to include the mainwindow header to another class, lets call that class A, and from that class A then add a dock to the main window.

        The problem is, that mainwindow already uses class A and has its header file included. So i get a circular dependency.

        If i use forward declaration in class A and type "class MainWindow;" i can not really use any functions of the main window class in class A.

        Is there someone with the same problem, or does someone have a solution on how to access the mainwindow class without a circular dependency?

        Thanks a lot
        Michael

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #2

        @tiegert said in Accessing mainwindow from another class:

        i have tried to include the mainwindow header to another class

        Why? Don't. And then your issue will go away.

        T 1 Reply Last reply
        0
        • JonBJ JonB

          @tiegert said in Accessing mainwindow from another class:

          i have tried to include the mainwindow header to another class

          Why? Don't. And then your issue will go away.

          T Offline
          T Offline
          tiegert
          wrote on last edited by
          #3

          @JonB how can i then access the main window class?

          I used something like MainWindow::addDockWidget(...) to add a dock to the main window.

          If i don't include the header how can i access the mainwindow class?

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #4

            Hi,

            If you want to communicate with your main window, use signals and slots.

            The fact that you start to have circular dependencies of that kind in a GUI application hints at an architectural issue.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            T 1 Reply Last reply
            1
            • SGaistS SGaist

              Hi,

              If you want to communicate with your main window, use signals and slots.

              The fact that you start to have circular dependencies of that kind in a GUI application hints at an architectural issue.

              T Offline
              T Offline
              tiegert
              wrote on last edited by
              #5

              @SGaist i did change a few things in the structure and now with signals and slots it works, thanks for the hint.

              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