Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Application does not quit correctly after a call to QTcpServer::listen fails
Forum Updated to NodeBB v4.3 + New Features

Application does not quit correctly after a call to QTcpServer::listen fails

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 603 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aka0
    wrote on last edited by
    #1

    Hello,
    I am using Qt 4.8.4 on Windows 8 and I have the following problem: when for some reason a call to QTcpServer::listen fails (for example because the address or the port number are not available) my application should display an error and quit.
    Instead of quitting completely though, the process keeps living for more or less three minutes (visible in the task manager) and can not be killed. After some time (as I said, more or less three minutes, but I didn´t measure exactly) it disappears by itself. During this time the port can not be used by other instances of the application of course.
    If the call to QTcpServer::listen was successful, this does not occur, I can close the server and terminate the application without problems. The port is available again immediately afterwards.
    I imagine this is somehow related to socket timeouts at system level, but it would be good to get a clear explanation and a solution for this, if possible.
    I attach a code example. With this example the problem can be reproduced on my machine. Note that in my example DataHandler is a dummy QObject which does nothing, so its code is irrelevant.

    Can anybody help?
    Thanks in advance!

    @
    #include <QtCore/QCoreApplication>
    #include <QTcpServer>

    #include "DataHandler.h"

    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);

    QTcpServer* server = new QTcpServer();

    bool ok = server->listen(QHostAddress::Any, 80);

    if (!ok)
    {
    server->close();
    delete server;
    return -1; //In this case the application does not quit correctly
    }

    DataHandler* dataHandler = new DataHandler();

    QObject::connect(server, SIGNAL(newConnection()), dataHandler, SLOT(sendData()));

    a.exec();

    delete server;
    delete dataHandler;

    return 0; //In this case the application quits correctly
    }
    @

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved