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. Problems with Qml+QtConcurrency on imx.6
Forum Updated to NodeBB v4.3 + New Features

Problems with Qml+QtConcurrency on imx.6

Scheduled Pinned Locked Moved Solved Mobile and Embedded
2 Posts 1 Posters 180 Views
  • 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.
  • R Offline
    R Offline
    r3d9u11
    wrote on 30 Jun 2020, 15:34 last edited by r3d9u11
    #1

    Hello.
    I've noted the different behavior of the same application on different platforms: x86_64 and ARM (imx6).

    I tried to call some parallel logic from event handler of QML.

    On x86_64 all works fine and clear.
    But on ARM QtConcurrency doesn't fire the body of function, BUT in the same time isStarted() and isRunning() both return 'true'.

    For example:
    main.qml

    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
        Component.onCompleted: NMgr.callOnAppWindowCompleted()
        onClosing: NMgr.callOnAppWindowClosed()
    
        Shortcut { sequence: "Ctrl+q"; onActivated: NMgr.callOnUserEvent() }
    }
    

    appnative.h

    class AppNative: public QObject
    {
        bool pflg = false;
        QFuture<void> plf;
        QFuture<void> pmf;
        QFuture<void> puf;
    
        QTimer* tlf;
        QTimer* tmf;
    
    Q_OBJECT public:
    
        explicit AppNative();
        virtual ~AppNative();
    
        Q_INVOKABLE void callOnAppWindowCompleted();
        Q_INVOKABLE void callOnAppWindowClosed();
        Q_INVOKABLE void callOnUserEvent();
    
    private:
    
        void parallelMemberFunc();
        void timerMemberFunc();
    };
    

    appnative.cpp

    AppNative::AppNative()
    {
        tlf = new QTimer(this);
        tmf = new QTimer(this);
    
        auto timerLambdaFunc = [&]() {
            qDebug() << "      1000: Hello from timer lambda function!";
        };
    
        connect(tlf, &QTimer::timeout, this, timerLambdaFunc);
        connect(tmf, &QTimer::timeout, this, &AppNative::timerMemberFunc);
    }
    
    AppNative::~AppNative()
    {
        plf.~QFuture();
        pmf.~QFuture();
    
        tlf->~QTimer();
        tmf->~QTimer();
    }
    
    void AppNative::parallelMemberFunc()
    {
        while (pflg) {
            qDebug() << "   500: Hello from parallel member function!";
            QThread::msleep(500);
        }
    }
    
    void AppNative::timerMemberFunc()
    {
        qDebug() << "         2000: Hello from timer member function!";
    }
    
    void AppNative::callOnAppWindowCompleted()
    {
        auto parallelLambdaFunc = [&]() {
            while (pflg) {
                qDebug() << "250: Hello from parallel lambda function!";
                QThread::msleep(250);
            }
        };
    
        pflg = true;
        plf  = QtConcurrent::run(parallelLambdaFunc);
        pmf  = QtConcurrent::run(this, &AppNative::parallelMemberFunc);
    
        tlf->start(1000);
        tmf->start(2000);
    }
    
    void AppNative::callOnAppWindowClosed()
    {
        pflg = false;
        plf.waitForFinished();
        pmf.waitForFinished();
    
        tlf->stop();
        tmf->stop();
    }
    
    void AppNative::callOnUserEvent()
    {
        qDebug() << "Try to run parallel event handler...";
        puf = QtConcurrent::run([] { qDebug() << "--> Hello from parallel event handler..."; });
    }
    

    x86_64 output:

    250: Hello from parallel lambda function!
    250: Hello from parallel lambda function!
    Try to run parallel event handler...
    --> Hello from parallel event handler...
             2000: Hello from timer member function!
          1000: Hello from timer lambda function!
       500: Hello from parallel member function!
    250: Hello from parallel lambda function!
    Try to run parallel event handler...
    --> Hello from parallel event handler...
    250: Hello from parallel lambda function!
    Try to run parallel event handler...
    --> Hello from parallel event handler...
       500: Hello from parallel member function!
    250: Hello from parallel lambda function!
    Try to run parallel event handler...
    --> Hello from parallel event handler...
    ...
    

    ARM:

    250: Hello from parallel lambda function!
    250: Hello from parallel lambda function!
    Try to run parallel event handler...
    250: Hello from parallel lambda function!
    Try to run parallel event handler...
    250: Hello from parallel lambda function!
          1000: Hello from timer lambda function!
    Try to run parallel event handler...
    250: Hello from parallel lambda function!
    Try to run parallel event handler...
    250: Hello from parallel lambda function!
    Try to run parallel event handler...
    250: Hello from parallel lambda function!
    Try to run parallel event handler...
    250: Hello from parallel lambda function!250: Hello from parallel lambda function!
    250: Hello from parallel lambda function!
    250: Hello from parallel lambda function!
    250: Hello from parallel lambda function!
    250: Hello from parallel lambda function!
          1000: Hello from timer lambda function!
    250: Hello from parallel lambda function!
    250: Hello from parallel lambda function!
    250: Hello from parallel lambda function!
    250: Hello from parallel lambda function!
             2000: Hello from timer member function!
          1000: Hello from timer lambda function!
    250: Hello from parallel lambda function!
    250: Hello from parallel lambda function!
    Try to run parallel event handler...
    250: Hello from parallel lambda function!
    Try to run parallel event handler...
    250: Hello from parallel lambda function!
          1000: Hello from timer lambda function!
    Try to run parallel event handler...
    250: Hello from parallel lambda function!
    Try to run parallel event handler...
    250: Hello from parallel lambda function!
    Try to run parallel event handler...
    250: Hello from parallel lambda function!
    Try to run parallel event handler...
    250: Hello from parallel lambda function!
    ...
    ...
    

    There were missed calls of parallel method with message"500:..." and parallel handler of user's event (hotkey Ctrl+q).
    In more complex application the same problem rise more often.

    Could anybody clarify, what I'm doing wrong?
    Why there is different behavior of the same application on different platforms?

    I can share full project of this simple test application.

    Thanks!

    R 1 Reply Last reply 30 Jun 2020, 16:35
    0
    • R r3d9u11
      30 Jun 2020, 15:34

      Hello.
      I've noted the different behavior of the same application on different platforms: x86_64 and ARM (imx6).

      I tried to call some parallel logic from event handler of QML.

      On x86_64 all works fine and clear.
      But on ARM QtConcurrency doesn't fire the body of function, BUT in the same time isStarted() and isRunning() both return 'true'.

      For example:
      main.qml

      Window {
          visible: true
          width: 640
          height: 480
          title: qsTr("Hello World")
          Component.onCompleted: NMgr.callOnAppWindowCompleted()
          onClosing: NMgr.callOnAppWindowClosed()
      
          Shortcut { sequence: "Ctrl+q"; onActivated: NMgr.callOnUserEvent() }
      }
      

      appnative.h

      class AppNative: public QObject
      {
          bool pflg = false;
          QFuture<void> plf;
          QFuture<void> pmf;
          QFuture<void> puf;
      
          QTimer* tlf;
          QTimer* tmf;
      
      Q_OBJECT public:
      
          explicit AppNative();
          virtual ~AppNative();
      
          Q_INVOKABLE void callOnAppWindowCompleted();
          Q_INVOKABLE void callOnAppWindowClosed();
          Q_INVOKABLE void callOnUserEvent();
      
      private:
      
          void parallelMemberFunc();
          void timerMemberFunc();
      };
      

      appnative.cpp

      AppNative::AppNative()
      {
          tlf = new QTimer(this);
          tmf = new QTimer(this);
      
          auto timerLambdaFunc = [&]() {
              qDebug() << "      1000: Hello from timer lambda function!";
          };
      
          connect(tlf, &QTimer::timeout, this, timerLambdaFunc);
          connect(tmf, &QTimer::timeout, this, &AppNative::timerMemberFunc);
      }
      
      AppNative::~AppNative()
      {
          plf.~QFuture();
          pmf.~QFuture();
      
          tlf->~QTimer();
          tmf->~QTimer();
      }
      
      void AppNative::parallelMemberFunc()
      {
          while (pflg) {
              qDebug() << "   500: Hello from parallel member function!";
              QThread::msleep(500);
          }
      }
      
      void AppNative::timerMemberFunc()
      {
          qDebug() << "         2000: Hello from timer member function!";
      }
      
      void AppNative::callOnAppWindowCompleted()
      {
          auto parallelLambdaFunc = [&]() {
              while (pflg) {
                  qDebug() << "250: Hello from parallel lambda function!";
                  QThread::msleep(250);
              }
          };
      
          pflg = true;
          plf  = QtConcurrent::run(parallelLambdaFunc);
          pmf  = QtConcurrent::run(this, &AppNative::parallelMemberFunc);
      
          tlf->start(1000);
          tmf->start(2000);
      }
      
      void AppNative::callOnAppWindowClosed()
      {
          pflg = false;
          plf.waitForFinished();
          pmf.waitForFinished();
      
          tlf->stop();
          tmf->stop();
      }
      
      void AppNative::callOnUserEvent()
      {
          qDebug() << "Try to run parallel event handler...";
          puf = QtConcurrent::run([] { qDebug() << "--> Hello from parallel event handler..."; });
      }
      

      x86_64 output:

      250: Hello from parallel lambda function!
      250: Hello from parallel lambda function!
      Try to run parallel event handler...
      --> Hello from parallel event handler...
               2000: Hello from timer member function!
            1000: Hello from timer lambda function!
         500: Hello from parallel member function!
      250: Hello from parallel lambda function!
      Try to run parallel event handler...
      --> Hello from parallel event handler...
      250: Hello from parallel lambda function!
      Try to run parallel event handler...
      --> Hello from parallel event handler...
         500: Hello from parallel member function!
      250: Hello from parallel lambda function!
      Try to run parallel event handler...
      --> Hello from parallel event handler...
      ...
      

      ARM:

      250: Hello from parallel lambda function!
      250: Hello from parallel lambda function!
      Try to run parallel event handler...
      250: Hello from parallel lambda function!
      Try to run parallel event handler...
      250: Hello from parallel lambda function!
            1000: Hello from timer lambda function!
      Try to run parallel event handler...
      250: Hello from parallel lambda function!
      Try to run parallel event handler...
      250: Hello from parallel lambda function!
      Try to run parallel event handler...
      250: Hello from parallel lambda function!
      Try to run parallel event handler...
      250: Hello from parallel lambda function!250: Hello from parallel lambda function!
      250: Hello from parallel lambda function!
      250: Hello from parallel lambda function!
      250: Hello from parallel lambda function!
      250: Hello from parallel lambda function!
            1000: Hello from timer lambda function!
      250: Hello from parallel lambda function!
      250: Hello from parallel lambda function!
      250: Hello from parallel lambda function!
      250: Hello from parallel lambda function!
               2000: Hello from timer member function!
            1000: Hello from timer lambda function!
      250: Hello from parallel lambda function!
      250: Hello from parallel lambda function!
      Try to run parallel event handler...
      250: Hello from parallel lambda function!
      Try to run parallel event handler...
      250: Hello from parallel lambda function!
            1000: Hello from timer lambda function!
      Try to run parallel event handler...
      250: Hello from parallel lambda function!
      Try to run parallel event handler...
      250: Hello from parallel lambda function!
      Try to run parallel event handler...
      250: Hello from parallel lambda function!
      Try to run parallel event handler...
      250: Hello from parallel lambda function!
      ...
      ...
      

      There were missed calls of parallel method with message"500:..." and parallel handler of user's event (hotkey Ctrl+q).
      In more complex application the same problem rise more often.

      Could anybody clarify, what I'm doing wrong?
      Why there is different behavior of the same application on different platforms?

      I can share full project of this simple test application.

      Thanks!

      R Offline
      R Offline
      r3d9u11
      wrote on 30 Jun 2020, 16:35 last edited by r3d9u11 7 Jan 2020, 08:45
      #2

      @r3d9u11 seems like related to resources limitations.
      if try to change QThreadPool::globalInstance()->setMaxThreadCount and set needed thread count, all work fine.

      1 Reply Last reply
      0

      1/2

      30 Jun 2020, 15:34

      • Login

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