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
QtWS25 Last Chance

Creating a new thread with QtConcurrent did not work

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 630 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.
  • M Offline
    M Offline
    makopo
    wrote on 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
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 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
      1
      • Christian EhrlicherC Christian Ehrlicher

        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 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.

        KroMignonK S 2 Replies Last reply
        0
        • M makopo

          @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.

          KroMignonK Offline
          KroMignonK Offline
          KroMignon
          wrote on 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

            @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 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
            1
            • S SimonSchroeder

              @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 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

              • Login

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