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. QSerialPort signals and slots broadcasting

QSerialPort signals and slots broadcasting

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 3 Posters 1.8k 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.
  • qtprogrammer123Q Offline
    qtprogrammer123Q Offline
    qtprogrammer123
    wrote on last edited by qtprogrammer123
    #1

    Im sharing one QSerialport between 4 place in app, im using tcpsocket to so i made connectivity class for communication select.

    class Connectivity : public QObject {
    
        Q_OBJECT
    
    public:
        int connectionType = 1;
        SerialThread *serial; //I need  in this app for sure.
        TCP *tcp;
    ...
    ctor
    ...
     connect(serial, SIGNAL(connected()), this, SLOT(onConnected()), Qt::QueuedConnection);
     connect(serial, SIGNAL(disconnected()), this, SLOT(onDisconnected()), Qt::QueuedConnection);
     connect(serial, SIGNAL(response(QString)), this, SLOT(onResponse(QString)), Qt::QueuedConnection);
     connect(serial, SIGNAL(error(QString)), this, SLOT(onError(QString)), Qt::QueuedConnection);
     connect(serial, SIGNAL(timeout(QString)), this, SLOT(onTimeout(QString)), Qt::QueuedConnection);
    ...
    

    I need good way to brooadcast anserws between that 4 places. Maybe make it in Connectivity object slots?

    thx

    Mam moc jak Harry Potter, w zębach mogę przenieść hotel.

    J.HilkJ 1 Reply Last reply
    0
    • qtprogrammer123Q qtprogrammer123

      Im think about make second param in sendMsg method with sender id, remeber it, and after response clean it. 3 objects replay similar data, and will be hard to select reciver by them, 4th sending big data in parts - send part, after recive OK, send next while data > 0

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #9

      @qtprogrammer123
      Yes, that will work fine.
      Its called a token design so whoever has the token, will get the reply.

      So last one to use sendMsg, will get next reply or all replies until someone else
      use sendMsg.

      1 Reply Last reply
      1
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi
        How do you know where the reply belongs?
        Is there some ID in data or how do you tell the places apart?
        OR do you want all places to get all answers at the same time?

        1 Reply Last reply
        0
        • qtprogrammer123Q qtprogrammer123

          Im sharing one QSerialport between 4 place in app, im using tcpsocket to so i made connectivity class for communication select.

          class Connectivity : public QObject {
          
              Q_OBJECT
          
          public:
              int connectionType = 1;
              SerialThread *serial; //I need  in this app for sure.
              TCP *tcp;
          ...
          ctor
          ...
           connect(serial, SIGNAL(connected()), this, SLOT(onConnected()), Qt::QueuedConnection);
           connect(serial, SIGNAL(disconnected()), this, SLOT(onDisconnected()), Qt::QueuedConnection);
           connect(serial, SIGNAL(response(QString)), this, SLOT(onResponse(QString)), Qt::QueuedConnection);
           connect(serial, SIGNAL(error(QString)), this, SLOT(onError(QString)), Qt::QueuedConnection);
           connect(serial, SIGNAL(timeout(QString)), this, SLOT(onTimeout(QString)), Qt::QueuedConnection);
          ...
          

          I need good way to brooadcast anserws between that 4 places. Maybe make it in Connectivity object slots?

          thx

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #3

          @qtprogrammer123 said in QSerialPort signals and slots broadcasting:

          Im sharing one QSerialport between 4 place in app,

          just to clarify,
          do you mean 1 app, 4 places
          or
          4 apps 1 Serialport

          ?


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          0
          • qtprogrammer123Q Offline
            qtprogrammer123Q Offline
            qtprogrammer123
            wrote on last edited by
            #4

            1 app 4 places: console, one object communication, second object communication...

            Mam moc jak Harry Potter, w zębach mogę przenieść hotel.

            mrjjM 1 Reply Last reply
            0
            • qtprogrammer123Q qtprogrammer123

              1 app 4 places: console, one object communication, second object communication...

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #5

              @qtprogrammer123
              But do you want all places to get same reply ?
              Els you need a way to know what reply goes where.
              If its ok that all get the same data, then a signal will do just fine.

              1 Reply Last reply
              0
              • qtprogrammer123Q Offline
                qtprogrammer123Q Offline
                qtprogrammer123
                wrote on last edited by
                #6

                I want reply only in one place - to place from i send data. ouu its sync communication

                Mam moc jak Harry Potter, w zębach mogę przenieść hotel.

                mrjjM 1 Reply Last reply
                0
                • qtprogrammer123Q qtprogrammer123

                  I want reply only in one place - to place from i send data. ouu its sync communication

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #7

                  @qtprogrammer123
                  well then you can either let the Connectivity handle it
                  by having 4 signals for data
                  and only emit the right one for the sender
                  Or disconnect and connect the Senders when you switch betwen them.

                  Can you tell from the data who should get it ? (i assume not)

                  1 Reply Last reply
                  0
                  • qtprogrammer123Q Offline
                    qtprogrammer123Q Offline
                    qtprogrammer123
                    wrote on last edited by
                    #8

                    Im think about make second param in sendMsg method with sender id, remeber it, and after response clean it. 3 objects replay similar data, and will be hard to select reciver by them, 4th sending big data in parts - send part, after recive OK, send next while data > 0

                    Mam moc jak Harry Potter, w zębach mogę przenieść hotel.

                    mrjjM 1 Reply Last reply
                    0
                    • qtprogrammer123Q qtprogrammer123

                      Im think about make second param in sendMsg method with sender id, remeber it, and after response clean it. 3 objects replay similar data, and will be hard to select reciver by them, 4th sending big data in parts - send part, after recive OK, send next while data > 0

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #9

                      @qtprogrammer123
                      Yes, that will work fine.
                      Its called a token design so whoever has the token, will get the reply.

                      So last one to use sendMsg, will get next reply or all replies until someone else
                      use sendMsg.

                      1 Reply Last reply
                      1
                      • qtprogrammer123Q Offline
                        qtprogrammer123Q Offline
                        qtprogrammer123
                        wrote on last edited by
                        #10

                        ok ths for help.

                        Mam moc jak Harry Potter, w zębach mogę przenieść hotel.

                        1 Reply Last reply
                        0
                        • qtprogrammer123Q Offline
                          qtprogrammer123Q Offline
                          qtprogrammer123
                          wrote on last edited by
                          #11

                          ouuu one more, better way is using 4 separate signals for anserws, connect/disconnect them everytime, or reciving them in 4 places and check token? I think making 4 separate signal is best way - i will check token only once after recive and broadcast anserw

                          Mam moc jak Harry Potter, w zębach mogę przenieść hotel.

                          mrjjM 1 Reply Last reply
                          0
                          • qtprogrammer123Q qtprogrammer123

                            ouuu one more, better way is using 4 separate signals for anserws, connect/disconnect them everytime, or reciving them in 4 places and check token? I think making 4 separate signal is best way - i will check token only once after recive and broadcast anserw

                            mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on last edited by
                            #12

                            @qtprogrammer123
                            well 4 separate will make more simple.
                            and signals is not expensive so i would go for that.
                            and then depending on the token, simply emit different ones.

                            1 Reply Last reply
                            1
                            • qtprogrammer123Q Offline
                              qtprogrammer123Q Offline
                              qtprogrammer123
                              wrote on last edited by
                              #13

                              ok ;] I think its all

                              Mam moc jak Harry Potter, w zębach mogę przenieść hotel.

                              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