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. Run a timer based slot concurrently
Forum Updated to NodeBB v4.3 + New Features

Run a timer based slot concurrently

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 401 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.
  • B Offline
    B Offline
    BigBen
    wrote on last edited by BigBen
    #1

    Hi,
    I have a slot called map_transfer(int init_map, float arr). I want to run this slot every 2 seconds and therefore, I have connected it to a timer. However, when I run this function, my entire GUI gets slowed down and gets stuck sometimes.
    The UI gets stuck because this function saves an image locally whenever it is called.

    Therefore, I want to run this slot concurrently, so that the GUI doesn't get stuck.

    How can I do so?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      You have many options:

      • have a QThread waiting for the job and trigger it's slot every 2 seconds using your timer
      • use QtConcurrent
      • use QtPromise

      (Z(:^

      1 Reply Last reply
      4
      • B Offline
        B Offline
        BigBen
        wrote on last edited by BigBen
        #3

        @sierdzio
        Thanks for your reply. I want to use QtConcurrent. But unable to understand how to make it work for my situation.

        I have the following:

         mytimer = new QTimer(this);
         connect(mytimer, SIGNAL(timeout()), this, SLOT(update_info()));
         timer->start(2000);
        

        The update_info() slot has the function map_transfer(int init_map, float arr) (the time consuming function):

        void MainWindow::update_info()
        {
            QString str = this->mypath;
            QByteArray backTrack = str.toLocal8Bit();
            char* mySpace = backTrack.data();
        
            int success =map_transfer(init_map, arr); //time consuming function to be run concurrently
        
            int myRet = transfer_to_file(str, arr);
        }
        

        the transfer_to_file function has to run after the map_transfer function has completed its run.

        J.HilkJ 1 Reply Last reply
        0
        • B BigBen

          @sierdzio
          Thanks for your reply. I want to use QtConcurrent. But unable to understand how to make it work for my situation.

          I have the following:

           mytimer = new QTimer(this);
           connect(mytimer, SIGNAL(timeout()), this, SLOT(update_info()));
           timer->start(2000);
          

          The update_info() slot has the function map_transfer(int init_map, float arr) (the time consuming function):

          void MainWindow::update_info()
          {
              QString str = this->mypath;
              QByteArray backTrack = str.toLocal8Bit();
              char* mySpace = backTrack.data();
          
              int success =map_transfer(init_map, arr); //time consuming function to be run concurrently
          
              int myRet = transfer_to_file(str, arr);
          }
          

          the transfer_to_file function has to run after the map_transfer function has completed its run.

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

          @BigBen
          https://github.com/DeiVadder/QtThreadExample

          and direct link to the concurrent subproject:
          https://github.com/DeiVadder/QtThreadExample/tree/master/projects/QtConcurrent


          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