Qt: fixed using of OpenCV in another Qt app (patch #919)
authorIlya Lysenkov <no@email>
Thu, 16 Jun 2011 13:20:50 +0000 (13:20 +0000)
committerIlya Lysenkov <no@email>
Thu, 16 Jun 2011 13:20:50 +0000 (13:20 +0000)
modules/highgui/src/window_QT.cpp
modules/highgui/src/window_QT.h

index 712d638..5ff586d 100755 (executable)
@@ -442,14 +442,11 @@ CvButtonbar* icvFindButtonbarByName( const char* button_name,QBoxLayout* layout)
 \r
 int icvInitSystem(int *c, char** v)\r
 {\r
-       static int wasInitialized = 0;\r
-\r
-       // check initialization status\r
-       if( !wasInitialized)\r
+       //"For any GUI application using Qt, there is precisely one QApplication object"\r
+       if(!QApplication::instance())\r
        {\r
                new QApplication(*c,v);\r
 \r
-               wasInitialized = 1;\r
                qDebug()<<"init done";\r
 \r
 #if defined( HAVE_QT_OPENGL )\r
@@ -700,6 +697,7 @@ CV_IMPL void cvShowImage( const char* name, const CvArr* arr )
 \r
 GuiReceiver::GuiReceiver() : _bTimeOut(false), nb_windows(0)\r
 {\r
+       doesExternalQAppExist = (QApplication::instance() != 0);\r
        icvInitSystem(&parameterSystemC, parameterSystemV);\r
 \r
        timer = new QTimer;\r
@@ -714,7 +712,10 @@ void GuiReceiver::isLastWindow()
        {\r
                delete guiMainThread;//delete global_control_panel too\r
                guiMainThread = NULL;\r
-               qApp->quit();\r
+               if(!doesExternalQAppExist)\r
+               {\r
+                       qApp->quit();\r
+               }\r
        }\r
 }\r
 \r
@@ -983,6 +984,9 @@ void GuiReceiver::destroyAllWindow()
 \r
        if (multiThreads)\r
        {\r
+               // WARNING: this could even close windows from an external parent app\r
+               //#TODO check externalQAppExists and in case it does, close windows carefully,\r
+               //      i.e. apply the className-check from below...\r
                qApp->closeAllWindows();\r
        }else{\r
 \r
index ed4088f..80de075 100644 (file)
@@ -121,6 +121,7 @@ public:
 \r
 private:\r
        int nb_windows;\r
+       bool doesExternalQAppExist;\r
 \r
 public slots:\r
     void createWindow( QString name, int flags = 0 );\r