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. Problem in using the QtConcurrent
Forum Updated to NodeBB v4.3 + New Features

Problem in using the QtConcurrent

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 2.2k 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.
  • MrErfanM Offline
    MrErfanM Offline
    MrErfan
    wrote on last edited by
    #1

    Hi ,
    192 Error Using Qt Concurrent !! What is wrong
    Please see the pictures link text

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #2

      There are actually 96 overloads of QtConcurrent::run and that's just a nasty way of compiler letting you know that none of them has parameter types matching what you fed it with (2 error lines per overload).

      You are passing as an argument a result of addCustomer function and I doubt that's what you meant.
      You should instead pass it an object pointer, a method pointer and a list of parameters. The run function will call the method in another thread for you. So, assuming addCustomer is a method of class Foo that takes a string parameter, you would call it like this:

      Foo* someInstance = ... 
      QtConcurrent::run(someInstance, &Foo::addCustomer, QString("Hello!"));
      

      If addCustomer is a free standing function (I doubt that but lets say it is) then you call it without an object pointer:

      QtConcurrent::run(&addCustomer, QString("Hello!"));
      
      1 Reply Last reply
      1
      • MrErfanM Offline
        MrErfanM Offline
        MrErfan
        wrote on last edited by MrErfan
        #3

        hi my bro thanks for your response ,Do not fix problem
        185 Error

        myclass.cpp
        void MyClass::addCustomer(QString NameVaFamily,QString Mob1,QString Mob2,QString Tell,QString TarikhSabt,QString Tozihat,QString Address)
        {
        ............
        }
        
        void MyClass::test()
        {
            QFuture<void> f = QtConcurrent::run(&addCustomer,QString("param"),QString("param"),QString("param"),QString("param"),QString("param"),QString("asd"),QString("param"));
            f.waitForFinished();
        }
        
        
        1 Reply Last reply
        0
        • jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Please read what Chris Kawa wrote again!
          What you are now trying only works if addCustomer is a function and not a method.

          If it is a method you have to do it like this:

          Foo* someInstance = ... 
          QtConcurrent::run(someInstance, &Foo::addCustomer, QString("Hello!"));
          

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • Chris KawaC Offline
            Chris KawaC Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Since addCustomer is a method of class MyClass and you're calling it inside another MyClass method you need the syntax from my first example, not the second one:

            QFuture<void> f = QtConcurrent::run(this, &MyClass::addCustomer,QString("param"),QString("param"),QString("param"),QString("param"),QString("param"),QString("asd"),QString("param"));
            
            1 Reply Last reply
            1
            • MrErfanM Offline
              MrErfanM Offline
              MrErfan
              wrote on last edited by
              #6

              I'm in MyClass I use the Qt Concurrent , and call this method (run3) in Qml , But after error
              please see this image : link text

              1 Reply Last reply
              0
              • jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                What are the errors you get now (they are not visible in the screenshot)?

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • MrErfanM Offline
                  MrErfanM Offline
                  MrErfan
                  wrote on last edited by
                  #8

                  Erorr : link text
                  Code : link text

                  1 Reply Last reply
                  0
                  • Chris KawaC Offline
                    Chris KawaC Offline
                    Chris Kawa
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    The error points to line 65, which is empty. Something did not build. Please clean and rebuild your solution.

                    The bigger problem though is your usage of QtConcurrent. Since you wait on the future (f.waitForFinished()), you are blocking the main thread waiting on asynchronous call to finish. This is actually slower than simply calling the function directly without QtConcurrent.

                    It makes no sense to start an asynchronous call and immediately wait for it to finish.
                    The whole point of QtConcurrent is to be able to do other things while the call is processed in another thread.

                    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