Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Execution freezes when sending QRunnable to QThreadpool
Forum Updated to NodeBB v4.3 + New Features

Execution freezes when sending QRunnable to QThreadpool

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 388 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.
  • J Offline
    J Offline
    John Howe
    wrote on last edited by
    #1

    In my application, I receive data from a signal in a slot call at a rate of 60Hz. To improve performance, I'm trying to break off chunks of data and send it to be processed in various QRunnables via QThreadpool.

    Right now I am just trying to implement the Hello World task from the QThreadPool page.

    As I've got it laid out, I should be getting Hello World every time the slot is called. But instead it runs one time and then the application freezes. Any ideas?

    J.HilkJ 1 Reply Last reply
    0
    • J John Howe

      In my application, I receive data from a signal in a slot call at a rate of 60Hz. To improve performance, I'm trying to break off chunks of data and send it to be processed in various QRunnables via QThreadpool.

      Right now I am just trying to implement the Hello World task from the QThreadPool page.

      As I've got it laid out, I should be getting Hello World every time the slot is called. But instead it runs one time and then the application freezes. Any ideas?

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @John-Howe said in Execution freezes when sending QRunnable to QThreadpool:

      Any ideas?

      You're ding something wrong ? 😜

      We will probably need code snippets to tell you anything remotely of value


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        John Howe
        wrote on last edited by
        #3

        From my .h:

        class HelloWorldTask : public QRunnable
        {
            void run() override;
        };
        

        Implementation:

        void HelloWorldTask::run()
        {
            qDebug() << "Hello world from thread" << QThread::currentThread();
        }
        

        Slot call (signal comes at 60Hz):

                    HelloWorldTask *hello = new HelloWorldTask();
                    pool->tryStart(hello);
        
        J.HilkJ 1 Reply Last reply
        0
        • J John Howe

          From my .h:

          class HelloWorldTask : public QRunnable
          {
              void run() override;
          };
          

          Implementation:

          void HelloWorldTask::run()
          {
              qDebug() << "Hello world from thread" << QThread::currentThread();
          }
          

          Slot call (signal comes at 60Hz):

                      HelloWorldTask *hello = new HelloWorldTask();
                      pool->tryStart(hello);
          
          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @John-Howe
          works fine by me

          class HelloWorldTask : public QRunnable
          {
          
          public:
              void run() override
              {
                  while (true) {
                      QThread::msleep(16);//60Hz, ca.
                      qDebug() << "Hello world from thread" << QTime::currentTime() << QThread::currentThread();
                  }
          
              }
          };
          
          int main(int argc, char *argv[])
          {
              QApplication app(argc, argv);
          //    QCoreApplication app(argc, argv);
          
              QLabel responsiveLabel("Move me");
              responsiveLabel.resize(200,200);
              responsiveLabel.show();
          
              HelloWorldTask *hello = new HelloWorldTask();
              // QThreadPool takes ownership and deletes 'hello' automatically
              QThreadPool::globalInstance()->tryStart(hello);
          
              return  app.exec();
          }
          

          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          2

          • Login

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