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. Creating a new thread with QtConcurrent did not work
Forum Updated to NodeBB v4.3 + New Features

Creating a new thread with QtConcurrent did not work

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 802 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.
  • M Offline
    M Offline
    makopo
    wrote on 21 Nov 2021, 14:36 last edited by
    #1

    Hello,

    I have a function that should run in another thread than the main/GUI-Thread. For this I want to use QtConcurrent::run().
    As descriped here it looks like a super simple thing.
    But when I implement this I get the compiler warning:
    No instance of overloaded function matches the argument list.

    //Testclass.cpp
    TestClass::TestClass() {
        QFuture<void> future = QtConcurrent::run(TestFunction);
    }
     
    void TestClass::TestFunction()
    {
    	qDebug() << "Do nothing.";
    }
    

    QtConcurrent is included in the .pro file and in the header file of the class (also QFuture).
    I think there is a problem with the void type. But why?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 21 Nov 2021, 14:38 last edited by
      #2

      It's not a warning but an error.
      Is TestClass::TestFunction() a static function? Otherwise it will not work since QtConcurrent::run() needs a pointer to a function, not a pointer to a class function (because it's not resolvable - c++ basics). Or pass a lambda to QtConcurrent::run()

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      M 1 Reply Last reply 21 Nov 2021, 15:30
      1
      • C Christian Ehrlicher
        21 Nov 2021, 14:38

        It's not a warning but an error.
        Is TestClass::TestFunction() a static function? Otherwise it will not work since QtConcurrent::run() needs a pointer to a function, not a pointer to a class function (because it's not resolvable - c++ basics). Or pass a lambda to QtConcurrent::run()

        M Offline
        M Offline
        makopo
        wrote on 21 Nov 2021, 15:30 last edited by
        #3

        @Christian-Ehrlicher
        Thank you! I tried Lambda expression and it works.
        Do you know if there there is a deeper tutorial or info material for the Concurrent module as the offical docs? I did not find something.

        K S 2 Replies Last reply 21 Nov 2021, 16:16
        0
        • M makopo
          21 Nov 2021, 15:30

          @Christian-Ehrlicher
          Thank you! I tried Lambda expression and it works.
          Do you know if there there is a deeper tutorial or info material for the Concurrent module as the offical docs? I did not find something.

          K Offline
          K Offline
          KroMignon
          wrote on 21 Nov 2021, 16:16 last edited by
          #4

          @makopo said in Creating a new thread with QtConcurrent did not work:

          I did not find something.

          Have you read this part of documentation:

          • For Qt 5: https://doc.qt.io/qt-5/qtconcurrentrun.html
          • For Qt 6 (some additionnal tools like QPromise): https://doc.qt.io/qt-6/qtconcurrentrun.html

          I think there is all you need to understand how to use QtConcurrent::run()

          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
          2
          • M makopo
            21 Nov 2021, 15:30

            @Christian-Ehrlicher
            Thank you! I tried Lambda expression and it works.
            Do you know if there there is a deeper tutorial or info material for the Concurrent module as the offical docs? I did not find something.

            S Offline
            S Offline
            SimonSchroeder
            wrote on 22 Nov 2021, 07:46 last edited by
            #5

            @makopo said in Creating a new thread with QtConcurrent did not work:

            Do you know if there there is a deeper tutorial or info material for the Concurrent module as the offical docs? I did not find something.

            You have to read the section about member functions in the official docs. Member functions always have an implicit this as parameter. The least you have to do is to specify the object on which to call the member function.

            M 1 Reply Last reply 22 Nov 2021, 09:42
            1
            • S SimonSchroeder
              22 Nov 2021, 07:46

              @makopo said in Creating a new thread with QtConcurrent did not work:

              Do you know if there there is a deeper tutorial or info material for the Concurrent module as the offical docs? I did not find something.

              You have to read the section about member functions in the official docs. Member functions always have an implicit this as parameter. The least you have to do is to specify the object on which to call the member function.

              M Offline
              M Offline
              makopo
              wrote on 22 Nov 2021, 09:42 last edited by
              #6

              Yes, its my mistake. I read over this section in the docs und had searched for other sources... :-/

              1 Reply Last reply
              0

              1/6

              21 Nov 2021, 14:36

              • Login

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