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. TcpSocket signal readyRead not received
Qt 6.11 is out! See what's new in the release blog

TcpSocket signal readyRead not received

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 4 Posters 5.2k 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.
  • VRoninV Offline
    VRoninV Offline
    VRonin
    wrote on last edited by
    #2

    Did you declare onReadyRead as slot?
    Otherwise, to be on the safe side, change connect(socket, SIGNAL(readyRead()),this, SLOT(onReadyRead())); to connect(socket, &QTcpSocket::readyRead,this, &CSocatMonitor::onReadyRead);

    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
    ~Napoleon Bonaparte

    On a crusade to banish setIndexWidget() from the holy land of Qt

    Catalin.OC 1 Reply Last reply
    1
    • VRoninV VRonin

      Did you declare onReadyRead as slot?
      Otherwise, to be on the safe side, change connect(socket, SIGNAL(readyRead()),this, SLOT(onReadyRead())); to connect(socket, &QTcpSocket::readyRead,this, &CSocatMonitor::onReadyRead);

      Catalin.OC Offline
      Catalin.OC Offline
      Catalin.O
      wrote on last edited by Catalin.O
      #3

      @VRonin ,onReadyRead is a part of public slots.
      I tried that you suggested and also

      connect(socket, &QIODevice::readyRead,this, &CSocatMonitor::onReadyRead);
      

      The result is the same.

      1 Reply Last reply
      0
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #4

        Are you blocking the event loop?

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        Catalin.OC 1 Reply Last reply
        0
        • VRoninV VRonin

          Are you blocking the event loop?

          Catalin.OC Offline
          Catalin.OC Offline
          Catalin.O
          wrote on last edited by
          #5

          @VRonin I'm not blocking anything(AFIK)...The connect is triggered, also, the errors...

          1 Reply Last reply
          0
          • VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #6

            How are you sending the data to this client?

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            Catalin.OC 1 Reply Last reply
            0
            • VRoninV VRonin

              How are you sending the data to this client?

              Catalin.OC Offline
              Catalin.OC Offline
              Catalin.O
              wrote on last edited by
              #7

              @VRonin Just typing into the stdio. This output is provided by socat over the TCP.

              Taz742T 1 Reply Last reply
              0
              • Catalin.OC Catalin.O

                @VRonin Just typing into the stdio. This output is provided by socat over the TCP.

                Taz742T Offline
                Taz742T Offline
                Taz742
                wrote on last edited by
                #8

                @Catalin.O said in TcpSocket signal readyRead not received:

                Just typing into the stdio. This output is provided by socat over the TCP.

                Can you post code?

                Do what you want.

                Catalin.OC 1 Reply Last reply
                0
                • Taz742T Taz742

                  @Catalin.O said in TcpSocket signal readyRead not received:

                  Just typing into the stdio. This output is provided by socat over the TCP.

                  Can you post code?

                  Catalin.OC Offline
                  Catalin.OC Offline
                  Catalin.O
                  wrote on last edited by
                  #9

                  @Taz742 You mean the headers and all the sources ?

                  Taz742T 1 Reply Last reply
                  0
                  • Catalin.OC Catalin.O

                    @Taz742 You mean the headers and all the sources ?

                    Taz742T Offline
                    Taz742T Offline
                    Taz742
                    wrote on last edited by
                    #10

                    @Catalin.O
                    Yes, it would be better.

                    Do what you want.

                    Catalin.OC 1 Reply Last reply
                    0
                    • Catalin.OC Catalin.O

                      I'm having the issue mentioned inside the subject when building an tcp client for a server that is created with socat. Is there someone that had the same issue ?

                      #redirect the stdio on tcp port 2728
                      socat - tcp-listen:2728,reuseaddr,fork

                      On the same machine, I'm running the code that following(more or less, because I'm changing the code at each 5 minutes in case I have a tip):

                      CSocatMonitor::CSocatMonitor(QObject *parent)
                          : QDialog(parent)
                      {
                          qDebug() << "The fun is starting...";
                      }
                      void CSocatMonitor::init()
                      {
                          socket =  new QTcpSocket(this);
                      
                          in.setDevice(socket);
                          in.setVersion(QDataStream::Qt_5_9);
                      
                          connect(socket, SIGNAL(readyRead()),this, SLOT(onReadyRead()));
                          connect(socket, &QAbstractSocket::connected,this, &CSocatMonitor::connected);
                          connect(socket, &QAbstractSocket::disconnected,this, &CSocatMonitor::disconnected);
                          connect(socket, QOverload<QAbstractSocket::SocketError>::of(&QAbstractSocket::error),
                                       this, &CSocatMonitor::getError);
                      
                          socket->connectToHost("127.0.0.1",2728);
                      
                      }
                      void CSocatMonitor::onReadyRead()
                      {
                          in.startTransaction();
                      
                          QString nextFortune;
                          in >> nextFortune;
                      
                          if (!in.commitTransaction())
                              return;
                      
                          QMessageBox::information(this, tr("Fortune Client"),
                                                   tr("The following data occurred: %1.")
                                                   .arg(nextFortune));
                          socket->flush();
                      
                      }
                      
                      void CSocatMonitor::connected()
                      {
                          qDebug() << "connected...";
                          QMessageBox::information(this, tr("connected..."),
                                                   tr("connected..."
                                                      "connected..."));
                          QMessageBox::information(this, tr("Fortune Client"),
                                                   tr("The following data(remaining length %1) occurred: %2.")
                                                   .arg(QString(socket->readAll()))
                                                   .arg(socket->readAll().length()));
                          socket->flush();
                      }
                      
                      void CSocatMonitor::disconnected()
                      {
                          QMessageBox::information(this, tr("DISconnected..."),
                                                   tr("DISconnected..."
                                                      "DISconnected..."));
                      }
                      void CSocatMonitor::getError(QAbstractSocket::SocketError socketError)
                      {
                           qDebug() << "Socket error:" << socketError;
                           QMessageBox::information(this, tr("Fortune Client"),
                                                    tr("The following error occurred: %1.")
                                                    .arg(socket->errorString()));
                      }
                      
                      kshegunovK Offline
                      kshegunovK Offline
                      kshegunov
                      Moderators
                      wrote on last edited by
                      #11

                      @Catalin.O said in TcpSocket signal readyRead not received:

                      in.startTransaction();

                      QString nextFortune;
                      in >> nextFortune;
                      
                      if (!in.commitTransaction())
                          return;
                      

                      Unless your server knows what Qt is and how it should send you QStrings through QDataStream version 5.9, then this should always fail and you'd get nowhere with your slot.

                      Read and abide by the Qt Code of Conduct

                      Catalin.OC 1 Reply Last reply
                      2
                      • Taz742T Taz742

                        @Catalin.O
                        Yes, it would be better.

                        Catalin.OC Offline
                        Catalin.OC Offline
                        Catalin.O
                        wrote on last edited by
                        #12

                        @Taz742 Ok....


                        class CSocatMonitor : public QDialog
                        .....
                        int main(int argc, char *argv[])
                        {
                        QApplication a(argc, argv);
                        MainWindow w;
                        w.show();
                        CSocatMonitor * monitor = CSocatMonitor::getInstance();
                        monitor->init();

                        return a.exec();
                        

                        }

                        1 Reply Last reply
                        0
                        • kshegunovK kshegunov

                          @Catalin.O said in TcpSocket signal readyRead not received:

                          in.startTransaction();

                          QString nextFortune;
                          in >> nextFortune;
                          
                          if (!in.commitTransaction())
                              return;
                          

                          Unless your server knows what Qt is and how it should send you QStrings through QDataStream version 5.9, then this should always fail and you'd get nowhere with your slot.

                          Catalin.OC Offline
                          Catalin.OC Offline
                          Catalin.O
                          wrote on last edited by
                          #13

                          @kshegunov Your suggestion solved my blocking point. 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