Questions tagged [qtimer]

QTimer is a timer class provided by the cross-platform Qt framework.

The QTimer class provides repetitive and single-shot timers.

The QTimer class provides a high-level programming interface for timers. To use it, create a QTimer, connect its timeout() signal to the appropriate slots, and call start(). From then on it will emit the timeout() signal at constant intervals.

The official Qt documentation can be found here for Qt 4.8 and here for Qt 5.

340 questions
35
votes
3 answers

Does a QTimer object run in a separate thread? What is its mechanism?

When I create a QTimer object in Qt 5, and start it using the start() member function, is a separate thread created that keeps track of the time and calls the timeout() function at regular intervals? For example, QTimer *timer = new…
GoodDeeds
  • 7,956
  • 5
  • 34
  • 61
17
votes
4 answers

how to add a 1 second delay using Qtimer

I currently have a method which is as follows void SomeMethod(int a) { //Delay for one sec. timer->start(1000); //After one sec SomeOtherFunction(a); } This method is actually a slot that is attached to a signal. I would like…
Rajeshwar
  • 11,179
  • 26
  • 86
  • 158
15
votes
3 answers

Qt timers cannot be stopped from another thread

Hy, I'm writing my first Qt program and getting now in troubles with: QObject::killTimer: timers cannot be stopped from another thread QObject::startTimer: timers cannot be started from another thread My program will communicate to a CANOpen bus for…
Matt
  • 169
  • 1
  • 1
  • 7
11
votes
5 answers

Error "QObject::startTimer: QTimer can only be used with threads started with QThread" many times when closing application

I know this has been asked many times before. I read all of those threads, and my case seems different. Everybody else who has this trouble has a few straightforward causes that I think I’ve ruled out, such as: Starting a timer with no event loop…
Johnny J
  • 113
  • 1
  • 1
  • 4
11
votes
3 answers

Why I get "QTimer can only be used with threads started with QThread" messages if I have no QTimer in my code?

When (and only when) I quit my application, these (and only these) repeated message appear on the command prompt: QObject::startTimer: QTimer can only be used with threads started with QThread QObject::startTimer: QTimer can only be used with…
iacopo
  • 663
  • 1
  • 7
  • 22
8
votes
4 answers

QObject::startTimer: Timers can only be used with threads started with QThread

I am trying to start a Timer in a worker thread's event loop, but I get this error: QObject::startTimer: Timers can only be used with threads started with QThread Whats wrong with this? #include #include #include class…
user2950911
  • 873
  • 3
  • 12
  • 19
8
votes
4 answers

Using QT, how to call function once after a certain interval, even if more calls may occur?

I am having a hard time wording this question even though I don't think its that complicated. I want to do something simalar to QTimer::singleshot() but I want it to still only call the SLOT once even if QTimer::singleshot() is called multiple…
sm11963
  • 93
  • 1
  • 1
  • 6
7
votes
1 answer

PyQt5: Timer in a thread

Problem Description I'm trying to make an application that collects data, processes it, displays it, and some actuation (open/close valves, etc). As a practice for future applications where I have some stricter time constraints, I want to run the…
robotHamster
  • 609
  • 1
  • 7
  • 24
7
votes
1 answer

QTimer setInterval without resetting remainingTime

I have an app written in QT that uses QTimer. It's basically a game and all the actions are controlled by the timer. Game includes the ability to increase\decrease the game speed. The code for increasing the speed is timerValue -= speedUpValue; …
DannyPhantom
  • 1,042
  • 10
  • 21
6
votes
2 answers

PyQt4 Results in QThread error

Using PyQt4 4.8.6 the code below produces the error QObject::startTimer: QTimer can only be used with threads started with QThread when a is used as the variable for QApplication, but it does not produce the error if cpp (or most anything else) is…
MES
  • 223
  • 2
  • 6
6
votes
5 answers

QTimer::SingleShot fired after object is deleted

// Example class class A : public QObject { Q_OBJECT void fun() { Timer::SingleShot(10, timerSlot); //rough code } public slot: void timerSlot(); } auto a = SharedPointer(new A); a->fun(); a->reset(); // a deleted In this…
JamesWebbTelescopeAlien
  • 3,547
  • 2
  • 30
  • 51
6
votes
1 answer

What happens if I have several overlapping QTimer

Suppose I have 2 QTimer objects with 10, 20 as their intervals. And suppose I want to run slot1() with timer 1 timeout signal and slot2 with timer 2. So running order of slot1 and slot2 is something like this : …
s4eed
  • 7,173
  • 9
  • 67
  • 104
5
votes
1 answer

How to use QTimers in GoogleTest

I encounter cases during unit testing where I want the timeout of some QTimer to fire some slot in some QObject. It is not immediately obvious how to do this and some common pitfalls to this testing.
shavera
  • 803
  • 1
  • 8
  • 18
5
votes
4 answers

How can I run a timer inside a QThread?

I would like to run a timer inside a QThread. I have written some code in which I am getting some error during the run time. What am I doing wrong? (Parent is QThread(0x1498d10), parent's thread is QThread(0x11272b0), current thread is…
Rsvay
  • 1,285
  • 2
  • 13
  • 36
4
votes
1 answer

Why is a call to QTimer::start() outside a QThread (event loop) not failing?

The documentation says In multithreaded applications, you can use QTimer in any thread that has an event loop. To start an event loop from a non-GUI thread, use QThread::exec(). Qt uses the timer's thread affinity to determine which thread…
Bob
  • 4,576
  • 7
  • 39
  • 107
1
2 3
22 23