QTcp socket multi threaded application



  • I have created a multithreaded qtcpserver which creates a new thread whenever a new incomming connection occurs . But when i get the data readyread signal is sometimes getting emitted and sometimes it is not getting emitted...

    Does anyone knows anything about this issue.??



  • How do you know it is not emitted? How did you connect to the new threads?
    Some code might give some insights.



  • I have kept a debug print in the readyread signal. When I am using in ubuntu it is sometimes printing and sometime not printing. In windows it is working .

    This is the way I am creating the thread

    NewConnection *newCon = new NewConnection(sock->socketDescriptor(),PresentTablesCount);
    qDebug()<<sock->socketDescriptor();
    connect(newCon,SIGNAL(finished()),newCon,SLOT(deleteLater()));
    newCon->start();

    in thread run i am using in this way

    socket = new QTcpSocket();
    if(!socket->setSocketDescriptor(this->socketDescriptor))
    {
    qDebug()<<"error in setting sock desc";
    return;
    }
    connect(socket, SIGNAL(readyRead()), this, SLOT(OnReadyRead()), Qt::DirectConnection);
    connect(socket, SIGNAL(disconnected()), this, SLOT(OnDisconnected()));
    exec();

    ReadyRead slot

    qDebug()<<"in ready read";
    QByteArray = socket->readAll();


Log in to reply
 

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