Unsolved Qt TcpMultiThread Server
-
Hey
I have some problem with my TCP Server.void MyThread::readyRead(){ //auto socket = qobject_cast<QTcpSocket *>(sender()); QByteArray Data = socket->readAll(); qDebug() << socketDescriptor <<"Data in : "<< Data; socket ->write(Data); //Its work //Send message for all Client (socket) for( int i=0; i < ClientList.count(); ++i ) { QTcpSocket* writeforsocket = ClientList.at(i); //crash here writeforsocket->write("Text"); //DIDINT WORK writeforsocket->flush(); writeforsocket->waitForBytesWritten(3000); //writeforsocket->write(CurrentImg); // Write The Encoded Image writeforsocket->flush(); } }
-
hi @Krizbiii and welocme
Most likely your ClientList does not contain a valid pointer to a QTcpSocket instance.
You should check that
-
I see a number of potential things going wrong here. Let's start with the most obvious one, what is
ClientList
? who owns it?As a separate but important point. Why are you using multithreading to manage TCP socket? if it's to allow multiple connections it's a misconception born from the fortune client/server example being not very clear.
You can check out this example for an hopefully clearer explanation