[Interest] QML Singleton and QTimer?

Jérôme Godbout godboutj at amotus.ca
Thu May 6 23:42:59 CEST 2021


You can check the thread affinity of an object and the current thread that will display the problem you encounter. Use a queued signal into the QTimer thread to sent the start (it will be delayed until the thread process the event, hopefully you do no need precision there).

Jérôme Godbout, B. Ing.

Software / Firmware Team Lead
O: (418) 682-3636 ext.: 114
C: (581) 777-0050
godboutj at dimonoff.com<mailto:godboutj at dimonoff.com>
[signature_93124102]<https://www.dimonoff.com/>
dimonoff.com<https://www.dimonoff.com/>
1015 Avenue Wilfrid-Pelletier,
Québec, QC G1W 0C4, 4e étage


From: Interest <interest-bounces at qt-project.org> on behalf of Jason H <jhihn at gmx.com>
Date: Thursday, May 6, 2021 at 5:34 PM
To: interestqt-project.org <interest at qt-project.org>
Subject: [Interest] QML Singleton and QTimer?
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?

_______________________________________________
Interest mailing list
Interest at qt-project.org
https://lists.qt-project.org/listinfo/interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20210506/fbcaa5fc/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 13927 bytes
Desc: image001.png
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20210506/fbcaa5fc/attachment.png>


More information about the Interest mailing list