PDA

View Full Version : Calling QApplication from a Non-QT app?



hickscorp
10th April 2007, 01:39
Hello all,

I have noticed some strange behavior in my app. So here is a quick summary of what i'm doing:
- I have a non-QT app (Photoshop).
- I'm creating a plugin which has to use Threading and Widgets (So i need a QApplication instance).
- Photoshop starts the application several times without "freeing" static data...
- In the main plugin method, i do like this:


bool bUserAccepted = false;
{
ILogger::Log(LOGLEVEL_DEBUG, "Now starting the GUI...");
try {
// Initialize the QT engine.
int iArgC = 0;
static QApplication app (iArgC, NULL);
CWndMainImpl cMainWin((HWND)((PlatformData*)gFilterRecord->platformData)->hwnd, pInPlane, pOutPlane);
app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()) );
cMainWin.show();
app.exec();
bUserAccepted = cMainWin.bAccepted;
} catch(...) {
throw CGenericEx("Unable to display the GUI.", __FILE__, __LINE__);
}
}


I'm not getting any exception, at least at the begining. But after some times without restarting Photoshop, i'm getting some random errors... Sometimes Photoshop just crash, sometimes i get an unknown exception thrown out. So i'm wondering, can it be some static data QApplication allocates, which are supposed to be only allocated once? Maybe i'm doing something wrong with the connect slot to quit, what do you suggest?

Thanks for your answers ^^
Pierre.

hickscorp
10th April 2007, 16:18
Anyone have suggestions? Even guesses will help me :)

high_flyer
10th April 2007, 22:00
As far as I can tell it could be anything.
From what you posted its hard to tell where the problem resides.
You say there are some global variables - so it COULD be that two processes are trying to access the same resource at the same time. (so a problem between processes)
It could be a bug in your plugin.
Or may be this thread could be interesting:
http://www.qtcentre.org/forum/f-qt-programming-2/t-dll-application-6474.html
Both points are good for consideration - QApplication singelton, and staic variables initialization.
At least for me there is too little information to tell.