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();@

    to

    @onClicked: dummyLoop.process();@

    The C++ process is as follows:

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

    QEventLoop loop;
    QTimer timer;
    timer.setSingleShot(true);
    connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
    timer.start(5000);
    loop.exec&#40;&#41;;
    
    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
    
    DummyLoop{
        id: dummyLoop
    }
    
    BusyIndicator{
        id: busy
        anchors.centerIn: parent
        running: true
    }
    
    Timer{
        id: loopTimer
        interval: 1000
        running: false
    
        onTriggered: {
            dummyLoop.process();
        }
    
    }
    
    Button{
        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.