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

pull/13383/head
Ilya Lysenkov 14 years ago
parent 8d8ef596c8
commit 0565a9456d
  1. 16
      modules/highgui/src/window_QT.cpp
  2. 1
      modules/highgui/src/window_QT.h

@ -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 )
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,7 +712,10 @@ void GuiReceiver::isLastWindow()
{ {
delete guiMainThread;//delete global_control_panel too delete guiMainThread;//delete global_control_panel too
guiMainThread = NULL; guiMainThread = NULL;
qApp->quit(); if(!doesExternalQAppExist)
{
qApp->quit();
}
} }
} }
@ -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:
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 );

Loading…
Cancel
Save