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.
  • M Offline
    M Offline
    MrErfan
    wrote on 9 Feb 2016, 19:52 last edited by
    #1

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

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on 9 Feb 2016, 20:20 last edited by Chris Kawa 2 Sept 2016, 20:22
      #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
      • M Offline
        M Offline
        MrErfan
        wrote on 10 Feb 2016, 09:22 last edited by MrErfan 2 Oct 2016, 09:23
        #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
        • J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 10 Feb 2016, 10:28 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
          • C Offline
            C Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on 10 Feb 2016, 10:50 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
            • M Offline
              M Offline
              MrErfan
              wrote on 10 Feb 2016, 13:45 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
              • J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 10 Feb 2016, 13:57 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
                • M Offline
                  M Offline
                  MrErfan
                  wrote on 10 Feb 2016, 14:02 last edited by
                  #8

                  Erorr : link text
                  Code : link text

                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    Chris Kawa
                    Lifetime Qt Champion
                    wrote on 10 Feb 2016, 15:20 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

                    1/9

                    9 Feb 2016, 19:52

                    • Login

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