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

Running a member function in a QtConcurrent thread



  • I have a member function that runs to call a device SDK. It works, but I need to run it in a thread.

    //Working method:
    void DtXrayDetector::startDeviceAcquisition(QString debugID) {
        writeDebugLogEntryWithMutex("DtxRayDetector::startDeviceAcquistions for " + debugID);
    
        _dt.xAcq->Snap();
    }
    
    //Desired method:
    void DtXrayDetector::startDeviceAcquisition(QString debugID) {
        writeDebugLogEntryWithMutex("DtxRayDetector::startDeviceAcquistions for " + debugID);
        QFuture<void> qf;
        qf = QtConcurrent::run(_dt.xAcq->Snap());
    
    }
    

    I get an error: No matching function for call to run.

    I'm guessing this is a syntax issue that I just don't understand. I've tried a couple of variations that haven't worked. Do you see what I need to do differently?



  • @dwilliams said in Running a member function in a QtConcurrent thread:

    Is _dt.xAcq as QObject sub-class instance and Snap() a slot?
    In this case, supposing xAcq class name ist XAcq you can do:

    qf = QtConcurrent::run(_dt.xAcq, &XAcq::Snap);
    


  • That worked. Thank you!



  • @dwilliams your welcome


Log in to reply