How to disable connection timer in QTcpSocket

  • Hello.
    QTcpSocket creates timer to handle connection timeout. I tried to use thousands of sockets (not a typicall use case, but anyway) and got this error messages:

    QEventDispatcherWin32::registerTimer: Failed to create a timer (The current process has used all of its system allowance of handles for Window Manager objects.)

    I think creating timer for every socket is huge wast of system resources when you use many sockets. I can handle timeouts manually using just one single timer. But I didn't find any option to disable built-in socket connection timer. How can do it?

    My environment: Qt 5.4, 5.5.1, Windows 8.1, Visual Studio 2013

  • Lifetime Qt Champion


    AFAIK, there's none, you should have to modify QAbtractSocket and build your own version of Qt for that.

    But use a single timeout for so many sockets ? Sounds strange.

    Out of curiosity, why do you need so many sockets ?

  • @SGaist

    you should have to modify QAbtractSocket

    Seems like you right. The code in 'qabstractsocket.cpp':

    // Start the connect timer.
    if (threadData->hasEventDispatcher()) {
        if (!connectTimer) {
            connectTimer = new QTimer(q);
            QObject::connect(connectTimer, SIGNAL(timeout()),
                             q, SLOT(_q_abortConnectionAttempt()),

    And there are no options to disable it. But I think it will be easy to patch it to make it work without connectTimer.

    But use a single timeout for thought of sockets ? Sounds strange.

    What else can I do to avoid handles exhaustion? I don't see any other options.

    Out of curiosity, why do you need so many sockets ?

    Just testing Qt abilities and limitations in this particular area.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.