PDA

View Full Version : Qt and dlls ?



probine
15th December 2006, 12:23
Let me make it simple:

I have a class that allows me to put together two words. You instantiate this class, pass two words to it, and you will get the words added together and capitalized.

You pass "hel" and "lo"

You get "HELLO"

Now, the question is:

How can I make a dll out of that class, so I can later on change some of its functionality without having to compile the whole program again ?

I want a dll for windows and a .so for Linux.

How ?

wysota
15th December 2006, 12:41
Create such a project file:

TEMPLATE=lib
CONFIG += dll
CONFIG -= qt # I'm not sure if you want this
SOURCES+=filename.cpp
HEADERS+=filename.h
qmake && (n)make should do it.

fullmetalcoder
15th December 2006, 12:49
Create a qmake project, specifying "TEMPLATE = lib" and maybe "CONFIG += shared"
Add an header which will hold some crucial macros, ideally it should be called $projectname$.h
In this file add the following code (some names may be changed...)

#ifdef _PROJECT_BUILD_
#if (defined(QT_SHARED) || defined(QT_DLL)) && !defined(QT_PLUGIN)
#define PROJECT_EXPORT Q_DECL_EXPORT
#else
#define PROJECT_EXPORT
#endif
#else
#define PROJECT_EXPORT Q_DECL_IMPORT
#endif


Then include this file in all headers containing classes definition meant to be exported and place this macro between the "class" keyword and your class name.

Compile your dll.

To link the created dll through qmake add the following line to your project file :

LIBS += -L$path/to/your/dll$ -l$name_of_your_dll_without_suffix$

And you're done!!!

probine
15th December 2006, 12:49
how about for Linux ?

wysota
15th December 2006, 14:12
For Linux my answer is sufficient :)