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

QTcpSocket readyRead destination

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 248 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
    #1

    Hi,
    i'm using single instance of QTcpSocket in class but im doing two operation on it - do i need to switch connected slot every operation / use two socket instance? Or its some easier way for it?

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

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

      I got one instance of QTcpSocket in class

      private:
         QTcpSocket *m_socket
      

      i need to revice readyRead and select reciving slot - got two of them

      void readProgress();
      void readStatus();
      

      with slot i needed depends from operation im doing reading progress or reading status.

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

      JonBJ 1 Reply Last reply
      0
      • qtprogrammer123Q qtprogrammer123

        Hi,
        i'm using single instance of QTcpSocket in class but im doing two operation on it - do i need to switch connected slot every operation / use two socket instance? Or its some easier way for it?

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

        @qtprogrammer123
        Your question is not clear. What "two operations" are you doing on on a QTcpSocket instance? Why are you thinking of switching connected slots? Something sounds wrong here.

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

          I got one instance of QTcpSocket in class

          private:
             QTcpSocket *m_socket
          

          i need to revice readyRead and select reciving slot - got two of them

          void readProgress();
          void readStatus();
          

          with slot i needed depends from operation im doing reading progress or reading status.

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

          JonBJ 1 Reply Last reply
          0
          • qtprogrammer123Q qtprogrammer123

            I got one instance of QTcpSocket in class

            private:
               QTcpSocket *m_socket
            

            i need to revice readyRead and select reciving slot - got two of them

            void readProgress();
            void readStatus();
            

            with slot i needed depends from operation im doing reading progress or reading status.

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

            @qtprogrammer123
            I suggest you probably want to have just one onReadyRead() slot always attached to the socket. What you do from there, e.g. call readProgress() or readStatus() is up to you. You can maintain state as to where you got to for deciding which to call if you wish.

            You could alternate which slot you attach if you wish, but that requires disconnecting the previous one each time.

            But be careful: readyRead() signal can be issued on either "partial" reads or "multiple reads". You may have to handle insufficient data received in one call as well as too much data. That will require a buffer to keep track. That's is why I'm thinking it may be easier to manage with a single slot so that the buffering can be handled in one place.

            If you know exactly what data your various states expect you might find QDataSteam transactions on the socket helpful, e.g. example https://wiki.qt.io/WIP-How_to_create_a_simple_chat_application.

            qtprogrammer123Q 1 Reply Last reply
            2
            • JonBJ JonB

              @qtprogrammer123
              I suggest you probably want to have just one onReadyRead() slot always attached to the socket. What you do from there, e.g. call readProgress() or readStatus() is up to you. You can maintain state as to where you got to for deciding which to call if you wish.

              You could alternate which slot you attach if you wish, but that requires disconnecting the previous one each time.

              But be careful: readyRead() signal can be issued on either "partial" reads or "multiple reads". You may have to handle insufficient data received in one call as well as too much data. That will require a buffer to keep track. That's is why I'm thinking it may be easier to manage with a single slot so that the buffering can be handled in one place.

              If you know exactly what data your various states expect you might find QDataSteam transactions on the socket helpful, e.g. example https://wiki.qt.io/WIP-How_to_create_a_simple_chat_application.

              qtprogrammer123Q Offline
              qtprogrammer123Q Offline
              qtprogrammer123
              wrote on last edited by
              #5

              @JonB thx for help

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

              1 Reply Last reply
              0
              • qtprogrammer123Q qtprogrammer123 has marked this topic as solved on

              • Login

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