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. I have a problem with QTcpSocket and Connect()!
Forum Updated to NodeBB v4.3 + New Features

I have a problem with QTcpSocket and Connect()!

Scheduled Pinned Locked Moved General and Desktop
12 Posts 3 Posters 3.1k 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.
  • J jalomic

    @xmaze said:
    Why you are using Thread ?
    Look this example http://doc.qt.io/qt-5/qtnetwork-fortuneclient-example.html

    X Offline
    X Offline
    xmaze
    wrote on last edited by
    #3

    @jalomic

    Because is more familiar to me and QThread is difficult at this moment for me!

    J 1 Reply Last reply
    0
    • X xmaze

      @jalomic

      Because is more familiar to me and QThread is difficult at this moment for me!

      J Offline
      J Offline
      jalomic
      wrote on last edited by
      #4

      @xmaze You not need to use threads at all.

      X 1 Reply Last reply
      0
      • J jalomic

        @xmaze You not need to use threads at all.

        X Offline
        X Offline
        xmaze
        wrote on last edited by xmaze
        #5

        @jalomic but i have one more thread for the data processing!

        J 1 Reply Last reply
        0
        • X xmaze

          @jalomic but i have one more thread for the data processing!

          J Offline
          J Offline
          jalomic
          wrote on last edited by
          #6

          @xmaze
          Signal not emitted because all data is received by socket. You need just read it.
          socket->read(BUFFER+p,1448);
          Here you need to check bytesAvailable() > 1448 and than read

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jalomic
            wrote on last edited by jalomic
            #7

            And forgot ! Of course you need to call readAll insted read. Because if new data will not send to socket - signal readyRead will never be emited ! And data will be lost

            X 1 Reply Last reply
            0
            • dheerendraD Offline
              dheerendraD Offline
              dheerendra
              Qt Champions 2022
              wrote on last edited by
              #8

              You may be hitting the even processing issue as signal/slots across thread works using events. Try moving the QTCP Socket object creation to new thread. Don't create the object in constructor. Another suggestion is that you work with single thread and see whether your idea works.

              Dheerendra
              @Community Service
              Certified Qt Specialist
              http://www.pthinks.com

              X 1 Reply Last reply
              4
              • dheerendraD dheerendra

                You may be hitting the even processing issue as signal/slots across thread works using events. Try moving the QTCP Socket object creation to new thread. Don't create the object in constructor. Another suggestion is that you work with single thread and see whether your idea works.

                X Offline
                X Offline
                xmaze
                wrote on last edited by
                #9

                @dheerendra can you be more clear? i cannot understand your suggestion! Thank you

                1 Reply Last reply
                0
                • J jalomic

                  And forgot ! Of course you need to call readAll insted read. Because if new data will not send to socket - signal readyRead will never be emited ! And data will be lost

                  X Offline
                  X Offline
                  xmaze
                  wrote on last edited by
                  #10

                  @jalomic But with ReadAll i cannot use pointers to manipulate the position of the buffer, so i cannot write the data and the end of the buffer ?
                  An other problem is that ReadAll needs a QbyteArray and this make the work complicated because i need the pointers and with QbyteArray is a class...

                  J 1 Reply Last reply
                  0
                  • X xmaze

                    @jalomic But with ReadAll i cannot use pointers to manipulate the position of the buffer, so i cannot write the data and the end of the buffer ?
                    An other problem is that ReadAll needs a QbyteArray and this make the work complicated because i need the pointers and with QbyteArray is a class...

                    J Offline
                    J Offline
                    jalomic
                    wrote on last edited by
                    #11

                    @xmaze
                    Oh
                    QByteArray array = socket ->readAll();
                    memcpy(BUFFER+p,array.data(),array.size())
                    p+=array.size();

                    X 1 Reply Last reply
                    0
                    • J jalomic

                      @xmaze
                      Oh
                      QByteArray array = socket ->readAll();
                      memcpy(BUFFER+p,array.data(),array.size())
                      p+=array.size();

                      X Offline
                      X Offline
                      xmaze
                      wrote on last edited by
                      #12

                      @jalomic thank you

                      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