QCoreApplication and QApplication in two threads (MATLAB communication using socket)
I'm facing a weird issue but before let me explain what I've done.
The goal is to make Matlab communicate with a Qt Gui application I've developped.
I choose communicating using sockets and shared memory.
I had to write a matlab Mex file which use Qt and particularly QLocalSocket.
In the mex file C function I had to instantiate a QCoreApplication otherwise QLocalSocket constructor will crash.
So basicaly the mex function instantiates a QLocalSocket, establishes connection to my Qt App Server and exchange data via QSharedMemory.
Everything is ok on the MATLAB side, when I call the mex funtion I get data from my Qt App.
Now, the idea is to wrap the MATLAB code in a Qt Plugin that will be loaded by my Qt GUI app.
I made a Dll of the matlab code using matlab compiler.
I made a Qt Plugin to wrap matlab DLL, and make all the Matlab Runtime initializations needed.
Everything is fine, my plugin is loaded but :
When I call the main matlab function which will call the mex function to establish the connection with Qt Gui App it crashes BUT only in release mode.
In Debug Mode, it works perfectly, I can launch my MATLAB calculation from my Qt Gui App, I see the matlab GUI and everything is ok.
The MATLAB code receives data via shared memory and so on.
But in release mode it crashes and I see the message :
"WARNING: QApplication was not created in the main() thread." and then it crashes.
Plugins are running in a different thread in my Application and I understand that only one instance of QApplication can run.
On Matlab environment, the mex function is like a Qt Console Application with its own QCoreApplication, just connecting a socket to get some data and then closing the QCoreApplication.
But I can't use QLocalSocket without an instance of QCoreApplication even if my socket does not use signals or slots.
My Question is : Why does it run perfectly in DEBUG and crash on ASSERT in Release Mode?
I'm using Qt 4.7.3 on Windows 7 64bit with MSVC++ 2008 SP1.
Thanks for any suggestions on how to bypass the ASSERT in release mode or to solve the issue in a good way.
Actually I'm trying to find another solution then sockets to connect MATLAB code to Qt App.