开发者

Strange class declaration

In Qt's qr开发者_如何学JAVAect.h I found class declaration starting like this:

class Q_CORE_EXPORT QRect {
};

As you can see there are two identifiers after class keyword. How shall I understand this?

Thank you.


Q_CORE_EXPORT is a macro that gets expanded to different values depending on the context in which it's compiled.

A snippet from that source:

#ifndef Q_DECL_EXPORT
#  ifdef Q_OS_WIN
#    define Q_DECL_EXPORT __declspec(dllexport)
#  elif defined(QT_VISIBILITY_AVAILABLE)
#    define Q_DECL_EXPORT __attribute__((visibility("default")))
#  endif
#  ifndef Q_DECL_EXPORT
#    define Q_DECL_EXPORT
#  endif
#endif
#ifndef Q_DECL_IMPORT
#  ifdef Q_OS_WIN
#    define Q_DECL_IMPORT __declspec(dllimport)
#  else
#    define Q_DECL_IMPORT
#  endif
#endif

// ...

#    if defined(QT_BUILD_CORE_LIB)
#      define Q_CORE_EXPORT Q_DECL_EXPORT
#    else
#      define Q_CORE_EXPORT Q_DECL_IMPORT
#    endif

Those values (__declspec(dllexport), __attribute__((visibility("default"))), etc.) are compiler-specific attributes indicating visibility of functions in dynamic libraries.


Q_CORE_EXPORT isn't an identifier. It's a platform-dependent macro, and it's used to signal a class that's intended to be used across library boundaries. In particular, it's defined by the Qt core library and used by other Qt libraries.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜