Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to exit main process when sub thread exit abnormally
Forum Updated to NodeBB v4.3 + New Features

How to exit main process when sub thread exit abnormally

Scheduled Pinned Locked Moved Solved Mobile and Embedded
6 Posts 3 Posters 866 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.
  • L Offline
    L Offline
    LengJianHanShuang
    wrote on 23 Oct 2019, 00:27 last edited by
    #1

    Hi,
    I am using QCoreAppication in my main to start a event loop(this can be seen as Main process?), and I create a thread to deal with captures from uvc camera. Here is the problem: During running, I pull out the camera, the imshow window of opencv will be closed, but the Main Process still can be seen background(ps -e | grep MyAPP), even I add "_Exit / exit / abort" ,the Main process still there and can't be closed.

    Does anyone know how to deal with this?thanks very much

    Follow your dreams

    J 1 Reply Last reply 23 Oct 2019, 04:56
    0
    • L LengJianHanShuang
      23 Oct 2019, 05:35

      @JKSH
      Thanks for your advice, I am new to Qt, does there any api of qt exist that I can use to deal with the disconnect of camera?
      And then even if I detect the disconnect of camera, I can exit current thread, but how should I do to tell the main process to exit?

      J Offline
      J Offline
      JKSH
      Moderators
      wrote on 23 Oct 2019, 05:55 last edited by
      #4

      @LengJianHanShuang said in How to exit main process when sub thread exit abnormally:

      does there any api of qt exist that I can use to deal with the disconnect of camera?

      It sounds like you are using OpenCV to read your camera? Use the same OpenCV API to detect the disconnection.

      It would be even better if your app doesn't quit when the camera is disconnected; instead, see if you can wait for the camera to re-connect again and re-open the imshow window.

      And then even if I detect the disconnect of camera, I can exit current thread, but how should I do to tell the main process to exit?

      QCoreApplication::quit() stops the main event loop.

      If your used a QThread to run your second thread, connect the QThread::finished() signal to the QCoreApplication::quit() slot.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      L C 2 Replies Last reply 31 Oct 2019, 02:26
      5
      • L LengJianHanShuang
        23 Oct 2019, 00:27

        Hi,
        I am using QCoreAppication in my main to start a event loop(this can be seen as Main process?), and I create a thread to deal with captures from uvc camera. Here is the problem: During running, I pull out the camera, the imshow window of opencv will be closed, but the Main Process still can be seen background(ps -e | grep MyAPP), even I add "_Exit / exit / abort" ,the Main process still there and can't be closed.

        Does anyone know how to deal with this?thanks very much

        J Offline
        J Offline
        JKSH
        Moderators
        wrote on 23 Oct 2019, 04:56 last edited by
        #2

        @LengJianHanShuang said in How to exit main process when sub thread exit abnormally:

        I pull out the camera

        Do not let the thread exit abnormally. Write code to stop the thread normally when your program detects that the camera has been disconnected.

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        L 1 Reply Last reply 23 Oct 2019, 05:35
        4
        • J JKSH
          23 Oct 2019, 04:56

          @LengJianHanShuang said in How to exit main process when sub thread exit abnormally:

          I pull out the camera

          Do not let the thread exit abnormally. Write code to stop the thread normally when your program detects that the camera has been disconnected.

          L Offline
          L Offline
          LengJianHanShuang
          wrote on 23 Oct 2019, 05:35 last edited by
          #3

          @JKSH
          Thanks for your advice, I am new to Qt, does there any api of qt exist that I can use to deal with the disconnect of camera?
          And then even if I detect the disconnect of camera, I can exit current thread, but how should I do to tell the main process to exit?

          Follow your dreams

          J 1 Reply Last reply 23 Oct 2019, 05:55
          0
          • L LengJianHanShuang
            23 Oct 2019, 05:35

            @JKSH
            Thanks for your advice, I am new to Qt, does there any api of qt exist that I can use to deal with the disconnect of camera?
            And then even if I detect the disconnect of camera, I can exit current thread, but how should I do to tell the main process to exit?

            J Offline
            J Offline
            JKSH
            Moderators
            wrote on 23 Oct 2019, 05:55 last edited by
            #4

            @LengJianHanShuang said in How to exit main process when sub thread exit abnormally:

            does there any api of qt exist that I can use to deal with the disconnect of camera?

            It sounds like you are using OpenCV to read your camera? Use the same OpenCV API to detect the disconnection.

            It would be even better if your app doesn't quit when the camera is disconnected; instead, see if you can wait for the camera to re-connect again and re-open the imshow window.

            And then even if I detect the disconnect of camera, I can exit current thread, but how should I do to tell the main process to exit?

            QCoreApplication::quit() stops the main event loop.

            If your used a QThread to run your second thread, connect the QThread::finished() signal to the QCoreApplication::quit() slot.

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            L C 2 Replies Last reply 31 Oct 2019, 02:26
            5
            • J JKSH
              23 Oct 2019, 05:55

              @LengJianHanShuang said in How to exit main process when sub thread exit abnormally:

              does there any api of qt exist that I can use to deal with the disconnect of camera?

              It sounds like you are using OpenCV to read your camera? Use the same OpenCV API to detect the disconnection.

              It would be even better if your app doesn't quit when the camera is disconnected; instead, see if you can wait for the camera to re-connect again and re-open the imshow window.

              And then even if I detect the disconnect of camera, I can exit current thread, but how should I do to tell the main process to exit?

              QCoreApplication::quit() stops the main event loop.

              If your used a QThread to run your second thread, connect the QThread::finished() signal to the QCoreApplication::quit() slot.

              L Offline
              L Offline
              LengJianHanShuang
              wrote on 31 Oct 2019, 02:26 last edited by
              #5

              @JKSH said in How to exit main process when sub thread exit abnormally:

              @LengJianHanShuang said in How to exit main process when sub thread exit abnormally:

              does there any api of qt exist that I can use to deal with the disconnect of camera?

              It sounds like you are using OpenCV to read your camera? Use the same OpenCV API to detect the disconnection.
              I am sorry for my late reply! yes, you are right, I am using opencv to read camera, but when I disconnect the camera, there is segmentation fault in my app, and most times it will exit abnormally. I don't know which opencv API can be used to listen the disconnection of camera, so I didn't deal with the event that camera has disconnected.

              It would be even better if your app doesn't quit when the camera is disconnected; instead, see if you can wait for the camera to re-connect again and re-open the imshow window.

              And then even if I detect the disconnect of camera, I can exit current thread, but how should I do to tell the main process to exit?

              QCoreApplication::quit() stops the main event loop.

              If your used a QThread to run your second thread, connect the QThread::finished() signal to the QCoreApplication::quit() slot.
              Thanks very much for your advice, it seems worked for me, I will give it a try.

              I was in business trip that time, I was able to restart the app with shell when it exit abnormally, It is a good choice to use your advice. Thanks again

              Follow your dreams

              1 Reply Last reply
              0
              • J JKSH
                23 Oct 2019, 05:55

                @LengJianHanShuang said in How to exit main process when sub thread exit abnormally:

                does there any api of qt exist that I can use to deal with the disconnect of camera?

                It sounds like you are using OpenCV to read your camera? Use the same OpenCV API to detect the disconnection.

                It would be even better if your app doesn't quit when the camera is disconnected; instead, see if you can wait for the camera to re-connect again and re-open the imshow window.

                And then even if I detect the disconnect of camera, I can exit current thread, but how should I do to tell the main process to exit?

                QCoreApplication::quit() stops the main event loop.

                If your used a QThread to run your second thread, connect the QThread::finished() signal to the QCoreApplication::quit() slot.

                C Offline
                C Offline
                Catherine55
                Banned
                wrote on 19 Nov 2019, 04:58 last edited by Catherine55
                #6
                This post is deleted!
                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