Important: Please read the Qt Code of Conduct -

Problem in using the QtConcurrent

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

  • Moderators

    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!"));

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

    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"));

  • Lifetime Qt Champion

    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!"));

  • Moderators

    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"));

  • 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

  • Lifetime Qt Champion

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

  • Erorr : link text
    Code : link text

  • Moderators

    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.

Log in to reply