Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Communication between widgets
Qt 6.11 is out! See what's new in the release blog

Communication between widgets

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
7 Posts 5 Posters 4.8k Views 2 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.
  • asttekinA Offline
    asttekinA Offline
    asttekin
    wrote on last edited by
    #1

    Hi all,

    I have to pass data from mainwidget to second widget.
    The serial port is processed data contionusly in the main widget.
    Data needs to be sent to a secondary screen.

    Can you help to do that?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mvuori
      wrote on last edited by
      #2

      When you send data from one widget (the processing one) to another widget (the one that puts things to the other screen), the default way in Qt is to send a signal from the first to the slot in the second widget...

      1 Reply Last reply
      1
      • asttekinA Offline
        asttekinA Offline
        asttekin
        wrote on last edited by
        #3

        Can you show an example?

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

          Hi,

          Qt's documentation is filed with these kind of examples and demos. You should be able to get them all together and work with the Qt. .

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

          1 Reply Last reply
          2
          • Pradeep KumarP Offline
            Pradeep KumarP Offline
            Pradeep Kumar
            wrote on last edited by Pradeep Kumar
            #5

            Hi,

            So you want to send data from mainwidget class to second widget. class
            Here is the sample code.

            class MainwidgetClass : public QObject{
            Q_OBJECT;
            ...
            public signals:
            void yourSignal();
            };

            ...

            class SecondWidgetClass: public QObject{
            Q_OBJECT;
            ...
            public slots:
            void slotFunc();
            }

            MainwidgetClass *youObject = new MainwidgetClass ;
            connect(MainwidgetClass , SIGNAL(yourSignal()), SecondWidgetClass, SLOT(someSlot()));

            so if you want to send the data from the first MainwidgetClass class then you have use emit call emit yourSignal();

            And establish the connect between the two classes. U will recieve data in slotFunc() of
            SecondWidgetClass Class.

            Pradeep Kumar
            Qt,QML Developer

            jsulmJ 1 Reply Last reply
            1
            • Pradeep KumarP Pradeep Kumar

              Hi,

              So you want to send data from mainwidget class to second widget. class
              Here is the sample code.

              class MainwidgetClass : public QObject{
              Q_OBJECT;
              ...
              public signals:
              void yourSignal();
              };

              ...

              class SecondWidgetClass: public QObject{
              Q_OBJECT;
              ...
              public slots:
              void slotFunc();
              }

              MainwidgetClass *youObject = new MainwidgetClass ;
              connect(MainwidgetClass , SIGNAL(yourSignal()), SecondWidgetClass, SLOT(someSlot()));

              so if you want to send the data from the first MainwidgetClass class then you have use emit call emit yourSignal();

              And establish the connect between the two classes. U will recieve data in slotFunc() of
              SecondWidgetClass Class.

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Pradeep-Kumar
              That's not valid code.
              It should be:

              MainwidgetClass *youObject = new MainwidgetClass ;
              SecondWidgetClass *secondWidget = new SecondWidgetClass();
              connect(youObject , SIGNAL(yourSignal()), secondWidget, SLOT(slotFunc()));
              

              You need pointer to class instances, you cannot pass a class to connect.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1
              • Pradeep KumarP Offline
                Pradeep KumarP Offline
                Pradeep Kumar
                wrote on last edited by Pradeep Kumar
                #7

                @jsulm
                Sorry for that how could i miss that.

                Mistake corrected.

                class MainwidgetClass : public QObject{
                Q_OBJECT;
                ...
                public signals:
                void yourSignal();
                };

                ...

                class SecondWidgetClass: public QObject{
                Q_OBJECT;
                ...
                public slots:
                void slotFunc();
                }

                MainwidgetClass *youObject = new MainwidgetClass ;
                SecondWidgetClass *secondWidget = new SecondWidgetClass;

                connect(youObject , SIGNAL(yourSignal()), secondWidget, SLOT(slotFunc()));

                Thanks for correcting me @jsulm

                Pradeep Kumar
                Qt,QML Developer

                1 Reply Last reply
                1

                • Login

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