Timer QML Component event blocks UI?

  • Hi there!

    I have Timer component with event onTriggered event connected to a C++ process. The C++ has event loop in it. Somehow, it blocks the UI thread (validated from the busy indicator stops running; please take a look at the code from: http://cl.ly/A1RZ) whenever the timer is triggered. (The process doesn't block the UI when it is connected to a onClicked event of a Button element). I'm on N950 Harmattan device.

    The complete code can be downloaded from here: http://cl.ly/A1RZ

    Is there a way to not block the UI when I call the C++ process?

    To prove that the onClicked doesn't block the UI (whenever it runs the C++ process) you can change the onClicked event from:

    @onClicked: loopTimer.start();@


    @onClicked: dummyLoop.process();@

    The C++ process is as follows:

    @void DummyProcessWithLocalEventLoop::process()
    qDebug() << "run local event loop";

    QEventLoop loop;
    QTimer timer;
    connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
    qDebug() << "local event loop done";


    The page asking the process

    @import QtQuick 1.1
    import com.nokia.meego 1.0
    import dummy 1.0

    Page {
    tools: commonTools

    id: container
        id: dummyLoop
        id: busy
        anchors.centerIn: parent
        running: true
        id: loopTimer
        interval: 1000
        running: false
        onTriggered: {
        anchors {
            horizontalCenter: parent.horizontalCenter
            top: busy.bottom
            topMargin: 10
        text: qsTr("run dummy loop")
        onClicked: loopTimer.start();


  • That the main event loop (for the UI) is blocked is absolutly clear. Your timer runns 5 seconds and you spin a sub event loop inside DummyProcessWithLocalEventLoop::process(). This event loop will not ├╝process events from the main event loop.

  • Thanks for your quick reply :-)

    What I couldn't understand is: the behavior between onClicked event and onTriggered is different. What is the explanation?

Log in to reply

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