[Interest] QML Singleton and QTimer?

Jason H jhihn at gmx.com
Thu May 6 23:34:02 CEST 2021


I'm trying to have a simple singleton class, but it doesn't appear that I can use timers?


HardwareInterface::HardwareInterface(QObject *parent) : QObject(parent)
{
	m_timer = new QTimer(this);

	connect(m_timer, &QTimer::timeout, this, [=](){
		qDebug() << Q_FUNC_INFO;
	});

	m_timer->start(100); // QObject::startTimer: Timers can only be used with threads started with QThread

}

main.cpp: int main() {
...
qmlRegisterSingletonInstance("com.company.example", 1, 0, "HardwareInterface", &hardwareInterface);
...

How do we go about using timers in singletons?



More information about the Interest mailing list