Correct me if i'm wrong - but as far as i can tell, Q_DECL_EXPORT and Q_DECL_IMPORT are the macros used by Qt when building a plugin. From an aesthetic viewpoint you should use your own when building an off-the-shelf dynamic library.
If i want to build an dynamic library (let's call it mylib), i include the following header called MyLibDef.h in every class header file whose interface i want to be exported to the dll.
#ifndef MY_LIBDEF_H_
#define MY_LIBDEF_H_
#if defined(WIN32)
# ifdef MY_LIB_DLL
# define MY_LIB_DLLMAPPING __declspec(dllexport)
# else
# define MY_LIB_DLLMAPPING __declspec(dllimport)
# endif
#else
# define MY_LIB_DLLMAPPING
#endif
#endif
#ifndef MY_LIBDEF_H_
#define MY_LIBDEF_H_
#if defined(WIN32)
# ifdef MY_LIB_DLL
# define MY_LIB_DLLMAPPING __declspec(dllexport)
# else
# define MY_LIB_DLLMAPPING __declspec(dllimport)
# endif
#else
# define MY_LIB_DLLMAPPING
#endif
#endif
To copy to clipboard, switch view to plain text mode
The class declarationt then looks like this:
class MY_LIB_DLLMAPPING Foo
: public QWidget...
class MY_LIB_DLLMAPPING Foo : public QWidget
...
To copy to clipboard, switch view to plain text mode
I then add the -D MY_LIB_DLL to the compiler flags when i compile the dll. When i use the headers in some app that links the library the MY_LIB_DLL is not set by default
and everything is fine.
Cutting-and-pasting-and-replacing MY_LIB with something other takes approximately 30 seconds - IMHO this ain't that much
Regarding the WIN32 symbol: I don't use qmake so it might be that WIN32 will not work but you can replace it with the symbol Q_OS_WIN spotted in one of the posts above.
Bookmarks