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

How to exit main process when sub thread exit abnormally

Scheduled Pinned Locked Moved Solved Mobile and Embedded
6 Posts 3 Posters 816 Views
  • 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.
  • LengJianHanShuangL Offline
    LengJianHanShuangL Offline
    LengJianHanShuang
    wrote on 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

    JKSHJ 1 Reply Last reply
    0
    • LengJianHanShuangL LengJianHanShuang

      @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?

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on 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

      LengJianHanShuangL C 2 Replies Last reply
      5
      • LengJianHanShuangL LengJianHanShuang

        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

        JKSHJ Offline
        JKSHJ Offline
        JKSH
        Moderators
        wrote on 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

        LengJianHanShuangL 1 Reply Last reply
        4
        • JKSHJ JKSH

          @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.

          LengJianHanShuangL Offline
          LengJianHanShuangL Offline
          LengJianHanShuang
          wrote on 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

          JKSHJ 1 Reply Last reply
          0
          • LengJianHanShuangL LengJianHanShuang

            @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?

            JKSHJ Offline
            JKSHJ Offline
            JKSH
            Moderators
            wrote on 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

            LengJianHanShuangL C 2 Replies Last reply
            5
            • JKSHJ JKSH

              @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.

              LengJianHanShuangL Offline
              LengJianHanShuangL Offline
              LengJianHanShuang
              wrote on 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
              • JKSHJ JKSH

                @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 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