Results 1 to 2 of 2

Thread: QTcpServer in a QCoreApplication

  1. #1
    Join Date
    Jul 2006
    Posts
    126
    Thanks
    17
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QTcpServer in a QCoreApplication

    Hi.

    I need to write a multi-threading QTcpServer only with QCoreApplication.

    This is my main() function:

    Qt Code:
    1. int main(int argc, char *argv[]){
    2. QCoreApplication app(argc, argv);
    3. Server server;
    4.  
    5. message("Server init...");
    6. if(!server.listen(QHostAddress::Any, port)){
    7. message("Server can't be initiated");
    8.  
    9. return -1;
    10. }
    11. message("Server initiated");
    12. while(server.isListening());
    13. message("Server closed");
    14.  
    15. return 0;
    16. }
    To copy to clipboard, switch view to plain text mode 

    But it nevers enters in the Server::incomingConnection(int socketDescriptor) function. I suspect that the problem is with while(server.isListening()); but I haven't found any example for QtCore apps, only for QtGui

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTcpServer in a QCoreApplication

    You need something like:
    Qt Code:
    1. while( ! end && server.waitForNewConnection() ) {
    2. // ...
    3. }
    4.  
    5. // or simply (if you server reacts on newConnection() signal):
    6. return app.exec();
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to jacek for this useful post:

    xgoan (23rd March 2007)

Similar Threads

  1. QCoreApplication!!!!
    By fellobo in forum Qt Programming
    Replies: 6
    Last Post: 17th January 2007, 00:56
  2. Replies: 6
    Last Post: 8th January 2007, 10:24
  3. QCoreApplication And QSqlDatabase
    By ball in forum Qt Programming
    Replies: 1
    Last Post: 24th May 2006, 07:58
  4. Replies: 3
    Last Post: 11th May 2006, 00:00
  5. QCoreApplication question
    By barnabyr in forum Newbie
    Replies: 5
    Last Post: 24th March 2006, 19:38

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.