PDA

View Full Version : using QThread without QApplication for a library ?



pl01
9th November 2010, 20:12
Hi,

I'm working on a library, this one canbe used with or without QT. So, I would like to use QThread features but without QApplication or at least find a way to create a DLL that is not bound to QT.

Thanks

Zlatomir
9th November 2010, 20:21
If you use QThread you are "bound" with Qt

You can for example use boost threads (http://www.boost.org/doc/libs/1_44_0/doc/html/thread.html) multi-platform thread library.

pl01
9th November 2010, 20:27
Thanks,

The problem is that I'm working on a C++ library... not a complete application !

Now, my library use boost 1.44. I'm currently porting my library from VS2008 to QT creator.

The problem is that I'm unable to build boost 1.44 for mingw and use it in QTCreator... see this post : http://www.qtcentre.org/threads/35840-QT-Creator-Boost-How-to-build-boost-for-QT

high_flyer
9th November 2010, 21:07
The problem is that I'm working on a C++ library... not a complete application !
What Zlatomir said still applies.

You can't use Qt object without linking to Qt.
You can use external sources such as boost, (if/when you succeed in building it) or just normal ptherads - this should be in the libpthread (POSIX theads) MinGW is shipped with, or you can implement your own Thread classes (but I would not recommend that).

pl01
9th November 2010, 21:17
There is no problem to be "linked" statically in QT :-P

But I don't need a QT Application... by example my library is used with Java or C# !!! So, I just need :
1 - Create a DLL with QT embeded in it
2 - Avoid the use of QApplication because it is not an application

Not sure it is possible !

Zlatomir
9th November 2010, 21:46
Disclaimer: i'm no expert, but i don't see a connection between QApplication and QThread, so you should be able to create and use QThreads in a dll.

If you use LGPL license for Qt, you might have some LGPL restrictions about static linking (as far as i know you must share your source too) so consult a lawyer if you decide to go that way.

wysota
9th November 2010, 22:52
But I don't need a QT Application... by example my library is used with Java or C# !!! So, I just need :
1 - Create a DLL with QT embeded in it
2 - Avoid the use of QApplication because it is not an application
In short - use QApplication (or QCoreApplication, to be more precise). If the word "application" stings your eyes, you can always write this line:

typedef QCoreApplication QLolipop;
and use QLolipop instead of QCoreApplication. It surely won't make your code become sweet and sticky. I would worry more about how you intend to run the event loop of your "not application".

pl01
10th November 2010, 07:29
Thanks,

But I don't need any event loop !!!! I just need a portable threading library !

wysota
10th November 2010, 10:05
But I don't need any event loop !!!!
If you don't need an event loop then you don't need an application object. And most probably you don't need any QThread objects as well. Just be aware most of Qt things require an event loop to work. Without it I think using Qt just for the QThread object is an overkill and it's much better to use boost or some other similar library.