PDA

View Full Version : Share QApplication instance (exe and dll)



cquinones
12th October 2007, 20:27
I'm building an application that links to a dll that uses QHttp to do some work. Both the exe and the dll link to Qt 4.3.2 static libs. The problem I'm running into is that QHttp in the dll does not share the same QApplication object as the UI in the exe. It isn't able to process events. Is there a way to solve this problem, since I can't just create a new QApplication instance?

wysota
12th October 2007, 21:29
You should retrieve the application instance by using the static method QCoreApplication::instance() (or qApp global pointer).

cquinones
12th October 2007, 21:44
That doesn't seem to work, since it will not be the same instance (a problem with sharing singletons across dlls).

wysota
12th October 2007, 22:54
Don't link to static libs then. It's not a problem of sharing singletons across dlls, but across static libs. Shared objects would work fine.

cquinones
13th October 2007, 02:19
It's not a problem of sharing singletons across dlls, but across static libs

You are correct. That's what I should have said above. I would love to just use the Qt dynamic libs but that's not an option for the project I'm working on. So... I'm still looking for a way to solve this issue.:(

wysota
13th October 2007, 10:41
If you link to Qt libs two times, you are wasting space. What is the reason of linking both the executable and the shared object against static Qt libraries?

cquinones
13th October 2007, 21:01
Thanks for helping me out on this one. The shared library is used by the Qt exe that I mentioned and another non-Qt application. When I launch from the non-Qt app I just create a QCoreApplication object to process events while the lib does its work.


What is the reason of linking both the executable and the shared object against static Qt libraries?

The Qt based exe links to (this is off the top of my head, I'm not near the machine I'm working on this... heh... it's the weekend :p):

qmain
qtcore
qtgui

The shared lib links to:

qtcore
qtnetwork
qtxml

Is there something I'm doing wrong here? :confused:

Once again, thanks for staying with me on this one. :)

wysota
13th October 2007, 22:54
You didn't understand my question. You said that you have to link statically. Why?

cquinones
17th October 2007, 19:48
You said that you have to link statically. Why?

It was a matter of not wanting to ship the Qt Dlls. This is not a decision that I had a big part in. :o

I will try to bring up the idea of using dynamic libraries instead of trying to link statically. Thanks for all your help. :)

gfunk
17th October 2007, 20:43
how about instead of linking to a dll, just building another stand-alone exe (that will do the QHttp work) that you just launch from your main exe?

fullmetalcoder
18th October 2007, 19:02
I'd suggest linking the DLL against ALL the Qt libs needed (by both app and dll itself) and then just linking the executable against the DLL but I'm not sure static linking would ensure all requested symbols would be embedded into the DLL....

wysota
18th October 2007, 19:10
It was a matter of not wanting to ship the Qt Dlls.

You ship other DLLs - like plugins, so what's the reason for not shipping Qt libs? This would reduce the volume of the final package. You can even strip down the Qt DLLs of everything you don't need if you want to to further reduce the size of the package.