QTcpSocket QIODevice::readyRead signal not emitted.



  • 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


  • Qt Champions 2018

    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



  • @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();
    }


  • Qt Champions 2018

    @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 Champions 2018

    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



  • @VRonin and @aha_1980,

    Thanks a lot!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.