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. QThread terminate

QThread terminate

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 2.5k 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.
  • M Offline
    M Offline
    MKara
    wrote on last edited by p3c0
    #1

    Hi everyone,

    I want to terminate QThread process while it is running. The running process is one action and takes too much time (ex. opening an image which size 1GB). When the main thread shows progress dialog, our worker thread try to open this image. And if the user clicks the cancel button on progress dialog, we want to terminate this process.
    The worker thread calls some 3rd party library functions. It means that we can't add any signal to this code and also we don't have an event loop in the run function. QThread::terminate() function doesn't work in this situation. Do you have any idea how we can terminate it?

    QThread* worker;
    connect(progressDialog, &ProgressDialog::canceled, [ this, worker ] () {
        worker->terminate();
        worker->wait(10);
        if (!worker->isRunning())      qDebug() << "thread is stopped";
        progressDialog->hide();
        progressDialog->deleteLater();
    });
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      What library are you using to load that image ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MKara
        wrote on last edited by
        #3

        Hi SGaist,
        I use OpenCascade 6.9.1 for this process. The problem is we couldn't terminate worker thread, while it is working.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          What exactly are you using from them ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • M Offline
            M Offline
            MKara
            wrote on last edited by
            #5

            Actually opening image just a sample example in my case for better understand. Let me tell the correct case.
            We are opening iges file and demonstrating it on Opencascade. For this process, we call IGESControl_Reader class. IGESControl_Reader::TransferRoots() function create OCC shapes after reading the iges file. If the iges file is too big, this process takes 4-5 minutes. When this function is completed successfully, it returns a TopoDS_Compound object which contains all shapes.
            If the user don't want to wait for 4-5 minutes, he/she just click the "Cancel" button on ProgressDialog, and then the process will be terminated. Because creating all OCC shapes is managed by a worker QThread, if we terminate this thread, the process will be cancelled.

            We can give more examples related to this issue. For example, it could be reading matrix in a file and then calculate inverse matrix with using one of the math library. If we don't have a chance to modify library source code, how could it be terminated this process by QThread?

            Because of that reason, I tried upper code block but it doesn't work. Is there any illogical situation?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              In that case you should contact the OpenCascade folks to see if there's an alternative to TransferRoots that transfers one root at a time and that you can then handle in a cancelable for loop or if they provide directly a way to cancel the operation.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1

              • Login

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