Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

error: no member named 'create' in 'QThread'



  • Greeting every one,

    I do compile this code for windows and it work good, but for Android it show me this warring error.

    void Handler_Transaction::saveObject(bool modeThread)
    {
    if(modeThread == true)
    {
    QThread *thread = QThread::create(
    this{ this->saveObject(false);}
    );
    thread->start();

        return;
    }
    

    }


  • Moderators

    Are you running at least Qt 5.10 on the android build system? QThread::create() is a pretty new function added in 5.10.



  • @ambershark yes, the prove that's work for windows.


  • Moderators

    @TuniDev Are you using C++17 on your android compiler? This function is also only available there according to the docs.. My guess here is no since I don't even know of a stable c++17 compiler for android.



  • @ambershark
    Yes, I use it.

    QT += sql core gui quick
    CONFIG += c++17
    android: QT += androidextras

    //*****************************************************

    I guess they did not implement yet for Android.
    Is there any other solution to run my function in separate thread, using this class as argument ?


  • Moderators

    @TuniDev Yea just adding CONFIG += C++17 doesn't mean the target compiler will actually support it. In this case the g++ you are using for android probably doesn't. I could be wrong though, easy to test if you were curious..

    There are a ton of ways to run in a new thread. If you'd like a simple fire and forget function to run concurrently then I would just use c++11's threading. You can of course use QThread, but you will need to use the signal/slot method or a derived QThread.

    Using just plain c++ you could do:

    std::thread myThread([&](YourObject *whatever) { whatever->yourFunc(); }, this);
    

    ** No guarantees this works, didn't test it or compile... check std c++ docs in case I'm remembering wrong. I don't use c++ threads much since I have QThread most of the time. :)

    I would verify that my assumption of missing c++17 support is true (I'm pretty sure that's the problem though), and if so make sure you at least have c++11 on that compiler. If not I recommend upgrading your compiler. The above code requires at least c++11.



  • I find the solution, hope that help some one.

    void Handler_Transaction::saveObject(bool modeThread)
    {
    if(modeThread == true)
    {
    //******************************************************
    // it work for me
    QtConcurrent::run( this{ this->saveObject(false);});
    );
    return;
    }

    //doing script of thread here //
    }


Log in to reply