QThread with QTimer connection issues

qthread qtimer
qtimer thread
qobject::starttimer: timers cannot be started from another thread
qtimer reset

Is there anythin wrong with this, it's giving me weird compilation errors:

candidate function not viable: no known conversion from 'void (QThread::*)(QThread::QPrivateSignal)' to 'const char *' for 2nd argument

QTimer timer;
connect(&timer, &QTimer::timeout, this, &ThisClass::runConnectionCheck);
QThread connectionThread;
connect(&connectionThread, &QThread::started, &timer, &QTimer::start);

There are 2 QTimer slots called start(), so the compiler has that confusion, so you should QOverload:

connect(&connectionThread, &QThread::started, &timer, QOverload<>::of(&QTimer::start));

Or static_cast<>():

connect(&connectionThread, &QThread::started, &timer,static_cast<void (QTimer::*)()>(&QTimer::start));

@KubaOber provides 2 options:




[&]{ timer.start(); }

QThread and Qtimer not work together, issue i am having at the moment is my QTimer unable to execute bool conctStat=QObject::connect(testObj->ioTimer, SIGNAL(timeout()),  A short history. Long long ago, subclass QThread and reimplement its run() function is the only recommended way of using QThread. This is rather intuitive and easy to used. But when SLOTS and Qt event loop are used in the worker thread, some users do it wro

That you face this problem to begin with is the result of a complication you've added: the connection is not necessary at all. You can start the timer right away and then move it. The timer won't fire until the control returns to the event loop in the thread where the timer is, and that doesn't happen in your code since the timer is moved to another thread before your code returns to the event loop (if any) that this code runs on.

This code does the job just as well:

// https://github.com/KubaO/stackoverflown/tree/master/questions/timer-move-start-53200294
#include <QtCore>
int main(int argc, char *argv[]) {
   QCoreApplication app(argc, argv);
   int fired = 0;

   QTimer timer;
   QThread connectionThread;
   QObject::connect(&timer, &QTimer::timeout, [&] {
      Q_ASSERT(QThread::currentThread() == &connectionThread);
      timer.moveToThread(qApp->thread());  // move the timer back to allow destruction



QThread and QTimer, Hi, I have a slot that is connected to QTimer's signal. is ready otherwise timer->​stop. but it doesn't work and it gives me the following error: When you connect objects that live in the same thread, you get a direct connection  It is important to remember that a QThread instance lives in the old thread that instantiated it, not in the new thread that calls run(). This means that all of QThread's queued slots and invoked methods will execute in the old thread. Thus, a developer who wishes to invoke slots in the new thread must use the worker-object approach; new slots

connect(&connectionThread, &QThread::started, &timer, &QTimer::start);

Because QTimer::start has two overloaded function. You must use the old convention to point out which one to use.


Using QTimer in a QThread, Problem is that you are doing that wrong! Note that your QThread belongs to main thread so default connection here is redirected through  Lambdas are just as usable no matter what the relative threads are. In most cases, there must be a QObject that determines the thread context in which the lambda is executing, as well as the lifetime of the lambda.

Qtimer problem, i am using qtimer for traffic light change in junction. i have created four calling connect(timer,SIGNAL(timeout()),this,SLOT(state2() )); same process for all . QObject with QTimer moved to QThread - QTimer::timeout() not  The problem is that there are many perfectly valid reasons to subclass QThread. With Qt 5.0 and Qt 4.8.4, the documentation of QThread was changed so the sample code does not involve sub-classing. Look at the first code sample of the Qt 4.8 QThread documentation (Update: link to archive.org since the newer documentation is fixed). It has many

How to avoid QTimer intervals being affected by graphical updates , but one of the easier ways are by connecting the signal started from QThread to an appropriate slot of the class which should hold the QTimer  This particular crash is caused because python collects the QApplication when the main() function exits, which is just before Python itself exits. PyQtGraph internally shuts down some of its callbacks when Python exits to avoid these errors; perhaps it should do this when the QApplication exits instead..

QTimer Class Reference, To use it, create a QTimer, connect its timeout() signal to the appropriate slots, and call To start an event loop from a non-GUI thread, use QThread.exec(). Time delay using QThread showing build issues Tag: c++ , qt , qt4 , qthread I am trying to implement the sleep function of QT Qthread, so I declared it in the header file as--