Commit 0565a945 authored by Ilya Lysenkov's avatar Ilya Lysenkov

Qt: fixed using of OpenCV in another Qt app (patch #919)

parent 8d8ef596
...@@ -442,14 +442,11 @@ CvButtonbar* icvFindButtonbarByName( const char* button_name,QBoxLayout* layout) ...@@ -442,14 +442,11 @@ CvButtonbar* icvFindButtonbarByName( const char* button_name,QBoxLayout* layout)
int icvInitSystem(int *c, char** v) int icvInitSystem(int *c, char** v)
{ {
static int wasInitialized = 0; //"For any GUI application using Qt, there is precisely one QApplication object"
if(!QApplication::instance())
// check initialization status
if( !wasInitialized)
{ {
new QApplication(*c,v); new QApplication(*c,v);
wasInitialized = 1;
qDebug()<<"init done"; qDebug()<<"init done";
#if defined( HAVE_QT_OPENGL ) #if defined( HAVE_QT_OPENGL )
...@@ -700,6 +697,7 @@ CV_IMPL void cvShowImage( const char* name, const CvArr* arr ) ...@@ -700,6 +697,7 @@ CV_IMPL void cvShowImage( const char* name, const CvArr* arr )
GuiReceiver::GuiReceiver() : _bTimeOut(false), nb_windows(0) GuiReceiver::GuiReceiver() : _bTimeOut(false), nb_windows(0)
{ {
doesExternalQAppExist = (QApplication::instance() != 0);
icvInitSystem(&parameterSystemC, parameterSystemV); icvInitSystem(&parameterSystemC, parameterSystemV);
timer = new QTimer; timer = new QTimer;
...@@ -714,8 +712,11 @@ void GuiReceiver::isLastWindow() ...@@ -714,8 +712,11 @@ void GuiReceiver::isLastWindow()
{ {
delete guiMainThread;//delete global_control_panel too delete guiMainThread;//delete global_control_panel too
guiMainThread = NULL; guiMainThread = NULL;
if(!doesExternalQAppExist)
{
qApp->quit(); qApp->quit();
} }
}
} }
GuiReceiver::~GuiReceiver() GuiReceiver::~GuiReceiver()
...@@ -983,6 +984,9 @@ void GuiReceiver::destroyAllWindow() ...@@ -983,6 +984,9 @@ void GuiReceiver::destroyAllWindow()
if (multiThreads) if (multiThreads)
{ {
// WARNING: this could even close windows from an external parent app
//#TODO check externalQAppExists and in case it does, close windows carefully,
// i.e. apply the className-check from below...
qApp->closeAllWindows(); qApp->closeAllWindows();
}else{ }else{
......
...@@ -121,6 +121,7 @@ public: ...@@ -121,6 +121,7 @@ public:
private: private:
int nb_windows; int nb_windows;
bool doesExternalQAppExist;
public slots: public slots:
void createWindow( QString name, int flags = 0 ); void createWindow( QString name, int flags = 0 );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment