Results 1 to 6 of 6

Thread: double QSignalMapper with QTcpServer/QTcpSocket

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

    Default double QSignalMapper with QTcpServer/QTcpSocket

    Hi guys,

    I have one QTcpServer that must deal with several QTcpSocket clients. For this purpose I wanted to use 2 QSignalMapper for the newConnection() and readyRead signals as follows:

    Qt Code:
    1. // this runs in a separate thread
    2. void myServerThread::run(){
    3.  
    4. for(count=0;count<numConn;count++){
    5. signalMapperAcceptConnection->setMapping( tcpServer[count], count);
    6. signalMapperReadData->setMapping( tcpClient[count], count);
    7. connect(tcpServer[count], SIGNAL(newConnection()), signalMapperAcceptConnection, SLOT(map()));
    8. }
    9. connect( signalMapperAcceptConnection, SIGNAL(mapped(int)), this, SLOT(acceptConnection(int)),
    10. Qt::DirectConnection);
    11. exec();
    12. }
    13.  
    14. void myServerThread::acceptConnection(int objectID){
    15. static unsigned short signalCounter = 0;
    16. tcpClient[objectID] = tcpServer[objectID]->nextPendingConnection();
    17. connect( tcpClient[objectID], SIGNAL(readyRead()), signalMapperReadData, SLOT(map()));
    18. signalCounter++;
    19. if(signalCounter == numConn)
    20. connect( signalMapperReadData, SIGNAL(mapped(int)), this, SLOT(startRead(int)), Qt::DirectConnection);
    21. }
    To copy to clipboard, switch view to plain text mode 

    The first signal mapper works fine, the signal newConnection() is mapped into the acceptConnection slot with the correct ID but the problem is with the second signalmapper. The signal readyRead() doesn't come, althought a client is sending data.

    Do you know what I'm doing wrong?

    Thanks in advance!

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: double QSignalMapper with QTcpServer/QTcpSocket

    I'm a little confused by your last connect statement. You only connect up the mapping when all connected slots are setup?

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

    Default Re: double QSignalMapper with QTcpServer/QTcpSocket

    well, I tried both, connect one per client comes, and only one time, when all clients has been connected. In my application the connection of the clients happens at the beggining of the programm and it's controlated, I mean thats not a chat application or something so... My application "trigers" the clients at the beggining, so that, they try to connect...

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: double QSignalMapper with QTcpServer/QTcpSocket

    If the code of run() you posted is your actual code, then it won't work. The sockets (and the signal mapper) need to be created in the thread you wish them to be handled by, otherwise your thread will do nothing apart making the connections.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Default Re: double QSignalMapper with QTcpServer/QTcpSocket

    thanks wysota,

    I created the sockets and the signal mappers in the run and I connected the signal of the sockets with the mappers in the run as well, but I still have the problem that I don't get the readRead() signal,

    shall I post the code?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: double QSignalMapper with QTcpServer/QTcpSocket

    Please post a minimal compilable example reproducing the problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QThread vs QTcpServer feat. QTcpSocket
    By ilyagoo in forum Newbie
    Replies: 6
    Last Post: 14th December 2009, 07:46
  2. QTcpServer QTcpSocket problem
    By jmsbc in forum Qt Programming
    Replies: 0
    Last Post: 20th November 2009, 17:42
  3. QTcpSocket, QTcpServer problem
    By frido in forum Qt Programming
    Replies: 3
    Last Post: 3rd April 2009, 23:16
  4. QTcpServer & QTcpSocket questions...
    By jxmot in forum Qt Programming
    Replies: 2
    Last Post: 24th April 2008, 21:38
  5. Replies: 3
    Last Post: 29th June 2007, 08:32

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.