Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Error on QtConcurrent::run
Qt 6.12 LTS is out! See what's new in the release blog

Error on QtConcurrent::run

Scheduled Pinned Locked Moved Solved Mobile and Embedded
15 Posts 4 Posters 3.6k Views 2 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.
  • P peter-70

    What is wrong with these code line:

    QtConcurrent::run(positionWidget, &PositionGroupbox::Select, false)
    

    positionWidget is a instance pointer of PositionGroupbox
    Select is public void with one bool parameter in the class PositionGroupbox

    The compiler shows me an error:

    error: no matching function for call to 'run'
                    synchronizer.addFuture(QtConcurrent::run(positionWidget, &PositionGroupbox::Select, false));
                                           ^~~~~~~~~~~~~~~~~
    

    Do you know what is wrong with the code?

    KroMignonK Offline
    KroMignonK Offline
    KroMignon
    wrote on last edited by KroMignon
    #5

    @peter-70 What is the type of synchronizer? It should be QFutureSynchronizer<void> to match PositionGroupbox::Select() signature.

    It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

    P 1 Reply Last reply
    0
    • P peter-70

      What is wrong with these code line:

      QtConcurrent::run(positionWidget, &PositionGroupbox::Select, false)
      

      positionWidget is a instance pointer of PositionGroupbox
      Select is public void with one bool parameter in the class PositionGroupbox

      The compiler shows me an error:

      error: no matching function for call to 'run'
                      synchronizer.addFuture(QtConcurrent::run(positionWidget, &PositionGroupbox::Select, false));
                                             ^~~~~~~~~~~~~~~~~
      

      Do you know what is wrong with the code?

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #6

      Does PositionGroupbox derive from QWidget directly or indirectly?

      Read and abide by the Qt Code of Conduct

      P 1 Reply Last reply
      0
      • KroMignonK KroMignon

        @peter-70 Perhaps you have to enable concurrent in your PRO file:

        QT += concurrent
        
        P Offline
        P Offline
        peter-70
        wrote on last edited by peter-70
        #7

        @KroMignon said in Error on QtConcurrent::run:

        QT += concurrent

        Good idea, but unfortunately it does not help

        J.HilkJ 1 Reply Last reply
        0
        • P peter-70

          @KroMignon said in Error on QtConcurrent::run:

          QT += concurrent

          Good idea, but unfortunately it does not help

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

          @peter-70
          if you forgot QT += concurrent inside your *pro file, you have to do a complete rebuild - deleting build folder running qmake - for it to take effect, after adding it!

          Did you do that?


          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.

          P 1 Reply Last reply
          0
          • kshegunovK kshegunov

            Does PositionGroupbox derive from QWidget directly or indirectly?

            P Offline
            P Offline
            peter-70
            wrote on last edited by
            #9

            @kshegunov

            Yes, PositionGroupbox derive from QWidget directly. But What does it matter?

            kshegunovK 1 Reply Last reply
            0
            • J.HilkJ J.Hilk

              @peter-70
              if you forgot QT += concurrent inside your *pro file, you have to do a complete rebuild - deleting build folder running qmake - for it to take effect, after adding it!

              Did you do that?

              P Offline
              P Offline
              peter-70
              wrote on last edited by
              #10

              @J.Hilk At first, I did not do it. Now I've deleted the output folder and the makefile. Then recreate the makefile and invoke rebuild my project. But that does not help either :-(

              1 Reply Last reply
              0
              • KroMignonK KroMignon

                @peter-70 What is the type of synchronizer? It should be QFutureSynchronizer<void> to match PositionGroupbox::Select() signature.

                P Offline
                P Offline
                peter-70
                wrote on last edited by peter-70
                #11

                @KroMignon

                It should be QFutureSynchronizer<void> to match PositionGroupbox::Select() signature

                Yes it is!

                Here is the code snippet:

                QFutureSynchronizer<void> synchronizer;
                
                    while ((rc = position.Fetch()) && rowIndex < itemsCount)
                    {
                        auto p = new Position;
                        p->Copy(&position);
                
                        auto positionWidget = new PositionGroupbox(p, this);
                        p->SetContainer(positionWidget);
                
                        synchronizer.addFuture(QtConcurrent::run(positionWidget, &PositionGroupbox::Select, false));
                
                KroMignonK 1 Reply Last reply
                0
                • P peter-70

                  @KroMignon

                  It should be QFutureSynchronizer<void> to match PositionGroupbox::Select() signature

                  Yes it is!

                  Here is the code snippet:

                  QFutureSynchronizer<void> synchronizer;
                  
                      while ((rc = position.Fetch()) && rowIndex < itemsCount)
                      {
                          auto p = new Position;
                          p->Copy(&position);
                  
                          auto positionWidget = new PositionGroupbox(p, this);
                          p->SetContainer(positionWidget);
                  
                          synchronizer.addFuture(QtConcurrent::run(positionWidget, &PositionGroupbox::Select, false));
                  
                  KroMignonK Offline
                  KroMignonK Offline
                  KroMignon
                  wrote on last edited by
                  #12

                  @peter-70 This sound very strange to me.

                  I have used QtConcurrent::run() and never run in this error.

                  I think you have include header:

                  #include <QtConcurrent/QtConcurrent>
                  

                  Can you show the declaration of PositionGroupbox::Select?

                  It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                  P 1 Reply Last reply
                  0
                  • KroMignonK KroMignon

                    @peter-70 This sound very strange to me.

                    I have used QtConcurrent::run() and never run in this error.

                    I think you have include header:

                    #include <QtConcurrent/QtConcurrent>
                    

                    Can you show the declaration of PositionGroupbox::Select?

                    P Offline
                    P Offline
                    peter-70
                    wrote on last edited by peter-70
                    #13

                    @KroMignon

                    Can you show the declaration of PositionGroupbox::Select?

                    Yes, the include is as you write it here. But the declaration of PositionGroupbox::Select is the right question and solution!!!

                    100 points for you! ;-)

                    The declaration is:

                    void Select(bool isSelected, bool refreshColors = false);
                    

                    Now I call

                    synchronizer.addFuture(QtConcurrent::run(positionWidget, &PositionGroupbox::Select, false, false));
                    

                    and everything is ok!

                    @all: Thank you very much! Specially for KroMignon :-)

                    KroMignonK 1 Reply Last reply
                    0
                    • P peter-70

                      @KroMignon

                      Can you show the declaration of PositionGroupbox::Select?

                      Yes, the include is as you write it here. But the declaration of PositionGroupbox::Select is the right question and solution!!!

                      100 points for you! ;-)

                      The declaration is:

                      void Select(bool isSelected, bool refreshColors = false);
                      

                      Now I call

                      synchronizer.addFuture(QtConcurrent::run(positionWidget, &PositionGroupbox::Select, false, false));
                      

                      and everything is ok!

                      @all: Thank you very much! Specially for KroMignon :-)

                      KroMignonK Offline
                      KroMignonK Offline
                      KroMignon
                      wrote on last edited by
                      #14

                      @peter-70 your welcome

                      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                      1 Reply Last reply
                      1
                      • P peter-70

                        @kshegunov

                        Yes, PositionGroupbox derive from QWidget directly. But What does it matter?

                        kshegunovK Offline
                        kshegunovK Offline
                        kshegunov
                        Moderators
                        wrote on last edited by
                        #15

                        @peter-70 said in Error on QtConcurrent::run:

                        Yes, PositionGroupbox derive from QWidget directly. But What does it matter?

                        It matters quite a lot. QWidget is not thread-safe and it's not reentrant. You can't touch anything QWidget-y outside the GUI thread, including creating the actual object. Failing to observe this is a race condition and ultimately a bug. That is to say, you have bigger problems than a syntax error.

                        Read and abide by the Qt Code of Conduct

                        1 Reply Last reply
                        3

                        • Login

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