PDA

View Full Version : Using dll's in QT



qtguy
29th June 2006, 14:31
hi guys

can we implement custom dll's in QT??

fullmetalcoder
29th June 2006, 15:11
hi guys

can we implement custom dll's in QT??

Excuse me but what do you call a "custom dll" ? :confused:
If you want to create a dll the only things you need are :

set TEMPLATE variable of your .pro file to "lib" ( TEMPLATE = lib )
add "dll" to the CONFIG variable ( CONFIG += dll )
create an header file like the one under and include it in every heaer of your dll that shall be accessible by the user (the coder that want to link to your dll)
declare all the functions, classes, variables to export as "symbols"
compile it and link an app to it...
Sample code for 3)



#include <QtCore>

#ifdef _DLL_BUILD_
#define DLL_API Q_DECL_EXPORT
#else
#define DLL_API Q_DECL_IMPORT
#endif



sample code for 4)



void DLL_API someFunction();

class DLL_API SomeClass
{
// definition
}


Notes :

you can replace DLL_API by any name you like... ;)
in the example I've given you have to add "_DLL_BUILD_" to the DEFINES variable of your project (only the dll, not the executables linked to it...)
the DLL_API stuff is rather useless if your dll is not meant to be portable. It is required on window$ only...