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

QRunnable derived class Exception Triggered



  • I have a class derived from QObject and QRunnable:

    class RDF : public QObject, QRunnable {
        Q_OBJECT:
    
    private:
        void run();
    

    The constructor:

    RDF::RDF(const char* cpszFullPath, QObject* pParent)
                : QObject(pParent), QRunnable(),
                  mblnComplete(false),
                  meLastError(RDF_file_ok),
                  mpdsIn(nullptr), mpobjFile(nullptr),
                  mlngBScans(0), mlngLastBscans(0)
    {
        if ( cpszFullPath != nullptr )
        {
            const QString cstrFullPath(cpszFullPath);
            if ( mobjReader.open(cstrFullPath) != true )
            {
                std::cerr << "Failed to open file: "
                          << cstrFullPath.toLatin1().data() << std::endl;
                return;
            }
            QThreadPool::globalInstance()->start(this);
        }
        mcnUpdate = QObject::connect(&mtmrUpdate, &QTimer::timeout,
            [this]()
            {
                if ( mblnComplete == true )
                {
                    emit complete(mlngBScans);
                    mtmrUpdate.stop();
                    close();
                    return;
                }
                if ( mlngLastBscans != mlngBScans )
                {
                    mlngLastBscans = mlngBScans;
                    emit bscansUpdate(mlngBScans);
                }
            }
        );
        mtmrUpdate.start(mscintUpdateInterval);
    }
    

    In the run implementation:

    void RDF::run() {
        //Do something
    }
    

    When the leaves the run function an exception is triggered:
    0d203cd7-eca8-4a8a-996a-b934e794a5f6-image.png


  • Lifetime Qt Champion

    @SPlatten How does stack trace look like?

    Consider this:
    "QThreadPool deletes the QRunnable automatically if autoDelete() returns true (the default)" from https://doc.qt.io/qt-5/qrunnable.html


  • Lifetime Qt Champion

    @SPlatten How does stack trace look like?

    Consider this:
    "QThreadPool deletes the QRunnable automatically if autoDelete() returns true (the default)" from https://doc.qt.io/qt-5/qrunnable.html



  • @jsulm , thank you, I will add setAutoDelete(false) to the constructor.


Log in to reply