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. Sending signals between 2 cpp files back and forth without circular dependency?

Sending signals between 2 cpp files back and forth without circular dependency?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 278 Views
  • 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.
  • S Offline
    S Offline
    StudentScripter
    wrote on last edited by StudentScripter
    #1

    Hello,
    what is the best approach to sending a string between two .cpp files without getting a circular dependency, without using a forward declaration?

    Both widgets are inside dockwidgets which are both created inside the mainwindow:

    mainwindow.cpp-->dockWidgetA.cpp-->QTreeView.cpp (send and receive a String here)

    mainwindow.cpp-->dockWidgetB.cpp-->TextEdit.cpp (send and receive a String here)

    Best regards
    StudentScripter

    Pl45m4P 1 Reply Last reply
    0
    • S StudentScripter

      Hello,
      what is the best approach to sending a string between two .cpp files without getting a circular dependency, without using a forward declaration?

      Both widgets are inside dockwidgets which are both created inside the mainwindow:

      mainwindow.cpp-->dockWidgetA.cpp-->QTreeView.cpp (send and receive a String here)

      mainwindow.cpp-->dockWidgetB.cpp-->TextEdit.cpp (send and receive a String here)

      Best regards
      StudentScripter

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #2

      @StudentScripter

      Depends. Signals and slots or pass it directly.
      Why should there be a circular dependency?
      You just dont include each others header :)
      MainWindow knows about its childs but the children shouldnt know exactly about MainWindow. The connection is established in your MainWindow


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      S 1 Reply Last reply
      3
      • Pl45m4P Pl45m4

        @StudentScripter

        Depends. Signals and slots or pass it directly.
        Why should there be a circular dependency?
        You just dont include each others header :)
        MainWindow knows about its childs but the children shouldnt know exactly about MainWindow. The connection is established in your MainWindow

        S Offline
        S Offline
        StudentScripter
        wrote on last edited by
        #3

        @Pl45m4 Yeah well but how can i pass from QTreeView.cpp to TextEdit.cpp? Thy don't know about each other and also Mainwindow.cpp does not know about the exact instances of QTreeView or TextEdit as they are declared to be children in their respective Dockwidget subclass.

        Pl45m4P 1 Reply Last reply
        0
        • S StudentScripter

          @Pl45m4 Yeah well but how can i pass from QTreeView.cpp to TextEdit.cpp? Thy don't know about each other and also Mainwindow.cpp does not know about the exact instances of QTreeView or TextEdit as they are declared to be children in their respective Dockwidget subclass.

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on last edited by Pl45m4
          #4

          @StudentScripter

          Then make use of the meta object tree (parent-child-structure).
          The QDockWidget should be a parent of each widget while QMainWindow is parent of each QDockWidget:

          In mainWindow something like:

          QTreeView *view = this->findChild<QTreeView *>("objectname"); // when there are multiple TreeViews, you can specify an object name to get the right one
          QTextEdit *edit = this->findChild<QTextEdit *>("textEdit_objectName"); // same here...
          
          connect(edit, &QTextEdit::sendString, view, &QTreeView::displayString);
          

          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          S 1 Reply Last reply
          0
          • Pl45m4P Pl45m4

            @StudentScripter

            Then make use of the meta object tree (parent-child-structure).
            The QDockWidget should be a parent of each widget while QMainWindow is parent of each QDockWidget:

            In mainWindow something like:

            QTreeView *view = this->findChild<QTreeView *>("objectname"); // when there are multiple TreeViews, you can specify an object name to get the right one
            QTextEdit *edit = this->findChild<QTextEdit *>("textEdit_objectName"); // same here...
            
            connect(edit, &QTextEdit::sendString, view, &QTreeView::displayString);
            
            S Offline
            S Offline
            StudentScripter
            wrote on last edited by
            #5

            @Pl45m4 Will try that, thank you very much for the quick response. :D

            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