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. QRunnable derived class Exception Triggered
Qt 6.11 is out! See what's new in the release blog

QRunnable derived class Exception Triggered

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 591 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by
    #1

    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

    Kind Regards,
    Sy

    jsulmJ 1 Reply Last reply
    0
    • SPlattenS SPlatten

      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

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      SPlattenS 1 Reply Last reply
      2
      • jsulmJ jsulm

        @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

        SPlattenS Offline
        SPlattenS Offline
        SPlatten
        wrote on last edited by
        #3

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

        Kind Regards,
        Sy

        1 Reply Last reply
        0

        • Login

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