Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QThread with QTimer connection issues

Is there anything 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;
timer.setInterval(3000);
connect(&timer, &QTimer::timeout, this, &ThisClass::runConnectionCheck);
QThread connectionThread;
timer.moveToThread(&connectionThread);
connect(&connectionThread, &QThread::started, &timer, &QTimer::start);
connectionThread.start();
like image 461
bardao Avatar asked Dec 12 '25 07:12

bardao


1 Answers

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:

C++14:

qOverload<>(&QTimer::start)

Lambda:

[&]{ timer.start(); }
like image 56
eyllanesc Avatar answered Dec 13 '25 20:12

eyllanesc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!