QT笔记——QT中c++11相关宏了解

一:Q_DISABLE_COPY(Class)

#define Q_DISABLE_COPY(Class) \
    Class(const Class &) Q_DECL_EQ_DELETE;\
    Class &operator=(const Class &) Q_DECL_EQ_DELETE;

这是一个拷贝构造 和 赋值函数 ,可以在单利模式的时候使用,我们可以将系统自带的赋值 和 拷贝禁用
Q_DISABLE_COPY(Test) 展开后:

Test(const Test&) delete;
Test&operator=(const Test&) delete;

二:Q_DECL_EQ_DELETE
c++11中的 delete

#ifdef Q_COMPILER_DELETE_MEMBERS
# define Q_DECL_EQ_DELETE = delete
#else
# define Q_DECL_EQ_DELETE
#endif

三:Q_NULLPTR
c++11 中的 nullptr

#ifdef Q_COMPILER_NULLPTR
# define Q_NULLPTR         nullptr
#else
# define Q_NULLPTR         NULL
#endif

四:Q_DECL_EQ_DEFAULT
c++11 中的 default

#ifdef Q_COMPILER_DEFAULT_MEMBERS
#  define Q_DECL_EQ_DEFAULT = default
#else
#  define Q_DECL_EQ_DEFAULT
#endif

五:Q_WIDGETS_EXPORT
作用:导入 和 导出

#ifndef QT_STATIC
#  if defined(QT_BUILD_WIDGETS_LIB)
#    define Q_WIDGETS_EXPORT Q_DECL_EXPORT
#  else
#    define Q_WIDGETS_EXPORT Q_DECL_IMPORT
#  endif
#else
#  define Q_WIDGETS_EXPORT
#endif

间接转化为 :

#  define Q_DECL_EXPORT __declspec(dllexport)
#  define Q_DECL_IMPORT __declspec(dllimport)

QT 常用的 signals and slots

# define Q_SIGNALS public QT_ANNOTATE_ACCESS_SPECIFIER(qt_signal)
相当于  signals:
# define Q_SLOTS QT_ANNOTATE_ACCESS_SPECIFIER(qt_slot)
相当于: slots:
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值