Qt4: unresolved timer events

Mini Sample File main.cpp:

#include <iostream>
#include <QCoreApplication>

class MyApp : public QCoreApplication
{
private:
    int m_idtimer;

public:
    MyApp(int nargs, char* argc[]) : QCoreApplication(nargs, argc)
    {
        m_idtimer = startTimer(3000); // 3 segs.
    }

protected:
    void timerEvent(QTimerEvent* e)
    {
        char c = '\0';

        std::cout << "timerEvent" << std::endl;
        std::cin >> c;

        if (c == 'q') {
            killTimer(m_idtimer);
            quit();
        }
    }
};

int main(int nargs, char* argc[])
{
    MyApp app(nargs, argc);

    return app.exec();
}

Extra mini Makefile:

LDFLAGS = -I/usr/include/qt4 -I/usr/include/qt4/QtCore
LDLIBS = -lQtCore

Compilation and execution:

$ make main
g++   -I/usr/include/qt4/QtCore  main.cpp  -lQtCore -o main
$ ./main
timerEvent
1
timerEvent
2
timerEvent
3
timerEvent
q
$

Ok, and then, my question. Ive made this sample for the purpose of testing if timer events are cumulative.

When I execute the program main, the following happens:

  • The first message is timerEventdisplayed after 3 seconds, and a timerEvent()symbol is waiting.
  • I click 1on average.
  • After 3 seconds, a second message appears timerEvent(as expected).
  • I wait a few seconds (15 or more) and I click 2
  • A third message is displayed immediately (one timer event accumulates).
  • I click immediately 3.
  • 3 ( ).
  • q .

: ? ?

PD: Qt - 4.8, SO Ubuntu 13.04 ​​(linux) 3.8.0-19-generic. - Gnome 3.

+1
1

, timerEvent . Qt , . , , 3 , . , , .

( ) .

+1

Source: https://habr.com/ru/post/1610058/


All Articles