在Qt的qrect.h我發現類的聲明開始是這樣的:奇怪類聲明
class Q_CORE_EXPORT QRect {
};
正如你可以看到有class關鍵字後,兩個標識符。我該如何理解這一點?
謝謝。
在Qt的qrect.h我發現類的聲明開始是這樣的:奇怪類聲明
class Q_CORE_EXPORT QRect {
};
正如你可以看到有class關鍵字後,兩個標識符。我該如何理解這一點?
謝謝。
Q_CORE_EXPORT
是a macro that gets expanded to different values取決於它編譯的上下文。
甲來自該源的片段:
#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
這些值(__declspec(dllexport)
,__attribute__((visibility("default")))
等)是指示在動態庫中的函數的能見度編譯器特定的屬性。
Q_CORE_EXPORT不是標識符。這是一個與平臺相關的宏,它用來表示一個打算在圖書館邊界使用的類。特別是,它由Qt核心庫定義並被其他Qt庫使用。