[Solved]QT 5.4.1 QTimer using up all handles for Window Manager Objects

  • I am using a QTimer to trigger a recurring call to a function, however it eventually crashed with the following errors

    QEventDispatcherWin32::registerTimer: Failed to create a timer (The current process has used all of its system allowance of handles for Window Manager objects.)
    struct HWND__ *__cdecl qt_create_internal_window(const class QEventDispatcherWin32 *): CreateWindow() for QEventDispatcherWin32 internal window failed (The current process has used all of its system allowance of handles for Window Manager objects.)
    Qt: INTERNAL ERROR: failed to install GetMessage hook: 1158, The current process has used all of its system allowance of handles for Window Manager objects.

    And as stated in this link, timer objects take up these handles. Is there a way to stop this? My program needs to be running all the time without being restarted and without user input, and increasing the system allowance (as some people suggest) seems like it would just delay the crash rather than prevent it.

    Timer code

    QTimer *timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(mFunc()));

    The timer is not recreated anywhere else, or called multiple times.

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Despite the message, your QTimer is probably innocent, how many widgets/windows are you creating with your application ?

  • It is making 3 windows, 2 of which are web views which poll a server.

  • Lifetime Qt Champion

    Ok, then what does happen in mFunc ?

  • Hi,

    how @SGaist said the message says something about creating resources.
    You timer is called every 15 seconds so I guess the guilty code is inside myFunc(). Could you show it?

  • sure, here it is

     void MainWindow::mFunc()
         // send tim url thing
         QNetworkAccessManager *manager = new QNetworkAccessManager(this);
        QString url = makeURL(1,1);
        ui->s1_showing->setText("Screen 1 : " + url);
        s1_max = 24;
        QNetworkReply *reply21 = manager->get(QNetworkRequest(QUrl("myUrl.php?param=x")));
        connect(reply21, SIGNAL(finished()), this, SLOT(set_s1()));
        QString url = makeURL(2,1);
        ui->s2_showing->setText("Screen 2 : " + url);
        s2_max = 24;
        QNetworkReply *reply22 = manager->get(QNetworkRequest(QUrl("myUrl.php?param=x")));
        connect(reply22, SIGNAL(finished()), this, SLOT(set_s2()));

  • Actually I have since spotted what the problem was, As it turns out creating a new instance of QNetworkAccessManager every 15 seconds is not the best idea if you're not deleting them.

    The solution I went with was making *manager a class member.

Log in to reply

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