[Qt-interest] Trouble using a QTcpScoket in more then one thread

Bill Reece reece.bill at ymail.com
Tue Dec 1 04:39:17 CET 2009


I have an application that is really a server. There are several user threads representing users logged on via a QTCPSocket and there are several worker threads each processing data on a unique data model.   Now each process thread has a list of sockets that are subscribed to it and in each workter thread I write to the user socket. Something like:

WorkThread::dataReady(QByteArray &byteArray)
{
    QListIterator <QTcpSocket *> iter(socketList);
    while(iter.hasNext())
     socket = iter.next();
     socket->write(byteArray);
     // without this line below the client doest get any data
     socket->flush();
    // with the line above I get the following run time message:
   // "QSocketNotifier: socket notifiers cannot be enabled from another thread"
}

I would think sockets could be shared by different threads, but Qt seems to not like it. Any thoughts on the best way to do this without the warning messages is appreciated.


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091130/4cfc8cfb/attachment.html 


More information about the Qt-interest-old mailing list