2010-06-30 78 views
5

在Qt的qrect.h我发现类的声明开始是这样的:奇怪类声明

class Q_CORE_EXPORT QRect { 
}; 

正如你可以看到有class关键字后,两个标识符。我该如何理解这一点?
谢谢。

回答

9

Q_CORE_EXPORTa 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")))等)是指示在动态库中的函数的能见度编译器特定的属性。

5

Q_CORE_EXPORT不是标识符。这是一个与平台相关的宏,它用来表示一个打算在图书馆边界使用的类。特别是,它由Qt核心库定义并被其他Qt库使用。