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 QIODevice::readyRead signal not emitted.
Forum Updated to NodeBB v4.3 + New Features

QTcpSocket QIODevice::readyRead signal not emitted.

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 929 Views
  • 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.
  • A Offline
    A Offline
    AlmirMartinelli
    wrote on last edited by
    #1

    Hello guys

    I made a client library tpcip in QT, when I import this library into csharp console project, client connects to the server successfully (connected slot is emit) and when the server sends data to the client, the client does not receive the data, does not trigger signal ReadyRead is emitted.. If I make test in the QT console application, then it works!

    Git hub repositories:

    My library in QT
    https://github.com/almirtalktelecom/LibraryTcpIpQt.git

    csharp console project
    https://github.com/almirtalktelecom/CrmIntegracao.git

    QT Creator version 4.9.0
    QT version 5.12.2 (MSVC 2017, 32 bit)

    Microsoft Visual Studio Professional 2017
    Version 15.9.11
    VisualStudio.15.Release/15.9.11+28307.586
    Microsoft .NET Framework
    Version 4.7.03062

    How to fix this?

    Thanks.

    Almir

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

      The answer is you don't have an event loop.
      The a.exec(); in the C++ project starts an event loop that takes care of signals and slots. The C# project never calls that method

      "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

      A 1 Reply Last reply
      2
      • VRoninV VRonin

        The answer is you don't have an event loop.
        The a.exec(); in the C++ project starts an event loop that takes care of signals and slots. The C# project never calls that method

        A Offline
        A Offline
        AlmirMartinelli
        wrote on last edited by
        #3

        @VRonin

        Hello

        but in the C# anothers signals work fine, eg.: When the client C# send a data to server, the signal bytesWritten is trigger, see on figure console print "bytesWritten 13", and every send data, the message it's printed,
        where C# receives the signal bytesWritten. Thank you.

        0_1557940311942_Capturar.PNG
        In Qt

        // Constructor Class
        TcpClient::TcpClient(QObject *parent)
        : QObject(parent)
        , socket(new QTcpSocket(this))
        {
        .
        .
        connect(socket, &QIODevice::readyRead, this, &TcpClient::readData);
        connect(socket, SIGNAL(bytesWritten(qint64)),this, SLOT(bytesWritten(qint64)));
        .
        .
        }

        // This signal is trigger to C#
        void TcpClient::bytesWritten(qint64 bytes)
        {
        qDebug() << "bytesWritten " << bytes;
        }

        // But it's not!!!
        void TcpClient::readData()
        {
        ReadDataUser();
        }

        aha_1980A 1 Reply Last reply
        0
        • A AlmirMartinelli

          @VRonin

          Hello

          but in the C# anothers signals work fine, eg.: When the client C# send a data to server, the signal bytesWritten is trigger, see on figure console print "bytesWritten 13", and every send data, the message it's printed,
          where C# receives the signal bytesWritten. Thank you.

          0_1557940311942_Capturar.PNG
          In Qt

          // Constructor Class
          TcpClient::TcpClient(QObject *parent)
          : QObject(parent)
          , socket(new QTcpSocket(this))
          {
          .
          .
          connect(socket, &QIODevice::readyRead, this, &TcpClient::readData);
          connect(socket, SIGNAL(bytesWritten(qint64)),this, SLOT(bytesWritten(qint64)));
          .
          .
          }

          // This signal is trigger to C#
          void TcpClient::bytesWritten(qint64 bytes)
          {
          qDebug() << "bytesWritten " << bytes;
          }

          // But it's not!!!
          void TcpClient::readData()
          {
          ReadDataUser();
          }

          aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @AlmirMartinelli

          I can only quote @VRonin again:

          The answer is you don't have an event loop.

          Even your example may not work on every O/S or Qt version. Not running the event loop is undefined behavior for most Qt classes.

          Regards

          Qt has to stay free or it will die.

          A 1 Reply Last reply
          2
          • VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #5

            signals and slots living on the same thread are executed as they were direct calls to the slot, they don't require an event loop. The socket system, instead, requires the loop to run to be able to work

            "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

            1 Reply Last reply
            2
            • aha_1980A aha_1980

              @AlmirMartinelli

              I can only quote @VRonin again:

              The answer is you don't have an event loop.

              Even your example may not work on every O/S or Qt version. Not running the event loop is undefined behavior for most Qt classes.

              Regards

              A Offline
              A Offline
              AlmirMartinelli
              wrote on last edited by AlmirMartinelli
              #6

              @VRonin and @aha_1980,

              Thanks a lot!

              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