Results 1 to 2 of 2

Thread: QTcpServer in QThread signal problem

  1. #1
    Join Date
    Feb 2010
    Posts
    28
    Qt products
    Qt4
    Platforms
    Windows

    Default QTcpServer in QThread signal problem

    Hi everybody,

    I have a QMainWindow application with 3 instances of a QThread based class (secondThread). This class has one instance of another QThread class (thirdThread) with a QTcpServer object

    Qt Code:
    1. seconThread::run(){
    2.  
    3. tcpServer = new thirdThread();
    4. tcpServer->run();
    5.  
    6. }
    7.  
    8. thirdThread::run(){
    9.  
    10. tcpServer = new QTcpServer();
    11. connect(tcpServer, SIGNAL(newConnection()),SLOT(acceptConnection()), Qt::DirectConnection);
    12. if (tcpServer->listen(QHostAddress::Any, port)) {
    13. exec();
    14. }
    15. }
    16.  
    17. thirdThread::acceptConnection(){
    18. tcpClient = tcpServer->nextPendingConnection();
    19. connect(tcpClient, SIGNAL(readyRead()),SLOT(startRead()), Qt::DirectConnection);
    20.  
    21. }
    To copy to clipboard, switch view to plain text mode 

    If I only work with an instance of secondThread, it works properly, I get the signals accept connection and ready read but If I have more than one instance (I tried with two and three instances) I only get the signals accept and ready read for one of the objects. Is there a problem with the event loop (exec()) if I call it several times?

    Thanks in advance!

  2. #2
    Join Date
    Apr 2010
    Location
    Rostov-na-Donu, Russia
    Posts
    153
    Thanks
    2
    Thanked 26 Times in 23 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTcpServer in QThread signal problem

    Maybe it happened because your second QTcpServer can't listen the same port at the same ip-address as your first QTcpServer ?
    Try to change port number is each thread

Similar Threads

  1. QThread signal and slots problem
    By mero in forum Qt Programming
    Replies: 8
    Last Post: 8th May 2010, 01:56
  2. QTcpServer and QThread signal/slot problem
    By Diph in forum Qt Programming
    Replies: 4
    Last Post: 28th July 2009, 19:34
  3. QTcpServer + QThread
    By Alex Snet in forum Qt Programming
    Replies: 2
    Last Post: 14th April 2009, 21:46
  4. QThread + QTcpServer
    By Fastman in forum Qt Programming
    Replies: 4
    Last Post: 19th July 2007, 16:19
  5. Replies: 3
    Last Post: 15th April 2007, 19:16

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.