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?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 314 Views 3 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.
  • S Offline
    S Offline
    StudentScripter
    wrote on 26 Nov 2023, 12:10 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

    P 1 Reply Last reply 26 Nov 2023, 12:22
    0
    • S StudentScripter
      26 Nov 2023, 12:10

      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

      P Offline
      P Offline
      Pl45m4
      wrote on 26 Nov 2023, 12:22 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 26 Nov 2023, 14:24
      3
      • P Pl45m4
        26 Nov 2023, 12:22

        @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 26 Nov 2023, 14:24 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.

        P 1 Reply Last reply 26 Nov 2023, 14:51
        0
        • S StudentScripter
          26 Nov 2023, 14:24

          @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.

          P Offline
          P Offline
          Pl45m4
          wrote on 26 Nov 2023, 14:51 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 26 Nov 2023, 14:52
          0
          • P Pl45m4
            26 Nov 2023, 14:51

            @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 26 Nov 2023, 14:52 last edited by
            #5

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

            1 Reply Last reply
            0

            5/5

            26 Nov 2023, 14:52

            • Login

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