How Could I stop all timers in Qml?



  • Hello. All

    I use many timers in Qml side,
    I want to stop all timers in cpp file.
    How can I do?

    xxxx.qml
    Timer{
    ...
    }

    xxab.qml
    Timer{
    ...
    }
    ...

    xxxx.cpp
    // Want to stop all timers using in Qml


  • Moderators

    @W-Y-Kim There are many ways for eg. finding children, setting context property or using signals etc..
    Using findChildren it can be done as:

    QQuickView view;
    view.setSource(QUrl(QStringLiteral("qrc:/main.qml")));
    
    auto objList = view.rootObject()->findChildren<QObject *>(QString(), Qt::FindChildrenRecursively);
    
        for (const auto& obj: objList) {
            if (obj->inherits("QQmlTimer")) {
                obj->setProperty("running", false);
            }
        }
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.