[Interest] Problem creating a dll that uses Qt (mingw)

Lincoln Ramsay lincoln.ramsay at nokia.com
Tue Jan 17 02:00:44 CET 2012


On 01/17/2012 04:54 AM, ext Till Oliver Knoll wrote:
> I don't know what the *= operator is supposed to do, even though I think
> it exists.

It means "add these values to this variable unless they are already 
there". In pseudocode:

for each value (list) {
   if (!variable.contains(value))
     variable.append(value)
}

Or for an example:

FOO = bar # FOO contains (bar)
FOO += bar # FOO contains (bar, bar)
FOO *= foo bar # FOO contains (bar, bar, foo)

> On another note, Qt provides some "cross-platform" macros which expands
> to that __declspec stuff on Windows and to "nothing" on most other
> platforms. Can't remember its name right now, but I thing it's defined
> in the global namespace in qt.h or qt_global.h or something...

What you want is something like this (replace XXX with your library's name):

#include <QtCore/qglobal.h>

#if defined(Q_OS_WIN)
#  if defined(QT_NODLL)
#    undef QT_MAKEDLL
#    undef QT_DLL
#  elif defined(QT_MAKEDLL)
#    if defined(QT_DLL)
#      undef QT_DLL
#    endif
#    if defined(QT_BUILD_XXX_LIB)
#      define Q_XXX_EXPORT Q_DECL_EXPORT
#    else
#      define Q_XXX_EXPORT Q_DECL_IMPORT
#    endif
#  elif defined(QT_DLL)
#    define Q_XXX_EXPORT Q_DECL_IMPORT
#  endif
#endif

#if !defined(Q_XXX_EXPORT)
#  if defined(QT_SHARED)
#    define Q_XXX_EXPORT Q_DECL_EXPORT
#  else
#    define Q_XXX_EXPORT
#  endif
#endif



Then you define QT_BUILD_XXX_LIB when building your library.


-- 
Lincoln Ramsay - Senior Software Engineer
Qt Development Frameworks, Nokia - http://qt.nokia.com/



More information about the Interest mailing list