Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Timer QML Component event blocks UI?
Forum Updated to NodeBB v4.3 + New Features

Timer QML Component event blocks UI?

Scheduled Pinned Locked Moved Mobile and Embedded
3 Posts 2 Posters 4.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    diorahman
    wrote on last edited by
    #1

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

    }
    @

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      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.

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • D Offline
        D Offline
        diorahman
        wrote on last edited by
        #3

        Thanks for your quick reply :-)

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

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved