Results 1 to 2 of 2

Thread: Multiple QTcpServer instances and message queue

  1. #1
    Join Date
    Apr 2011
    Posts
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Multiple QTcpServer instances and message queue

    Some might have an idea what to do...

    There are 3 QTcpServers listening or 3 different ports. I override incomingConnection or connect signal newConnection; those produce the same behavior. The problem is that the 3 servers must do a fair bit of work before sending a response and while one server processes the incoming connection, another thread cannot receive a connection since the main application message queue is blocked (I can create QThreads to process later but that still costs some speed).

    So, how can I ensure that the 3 QTcpServer instances own their own message queue and work really independently and receive messages really independently too? I tried to make classes extending QThread, also tried moveToThread but I am getting the "QObject: Cannot create children for a parent that is in a different thread." error message when trying to do that (surprisingly setMaxPendingConnections works, no complaints from Qt, but when it comes to listen... then it does not work).

    Any idea?

  2. #2
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Multiple QTcpServer instances and message queue

    Hi,

    First, create a QThread derived class "myThreadClass"
    When a new incoming connection comes, you can create a "myThreadClass" object and pass the socketDescriptor to it. Finally call "myThreadClass->start()".
    There you can create a QTcpSocket with the socketDescriptor and finally call "exec()" to enter into the eventLoop. In "myThreadClass" you will have to do the "work".

    Hope it helps,
    Òscar Llarch i Galán

Similar Threads

  1. how to develop message queue in Qt
    By gauravg in forum Qt Programming
    Replies: 1
    Last Post: 2nd December 2011, 07:23
  2. how to create message queue in qt
    By gauravg in forum Qt Programming
    Replies: 1
    Last Post: 17th November 2011, 12:36
  3. Replies: 2
    Last Post: 19th October 2011, 09:30
  4. Multiple instances of QWebView
    By darious in forum Qt Programming
    Replies: 1
    Last Post: 11th October 2011, 07:55
  5. Inter-Process Communication : Message Queue ?
    By lllturtle in forum Qt Programming
    Replies: 5
    Last Post: 6th August 2011, 12:25

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.