Qt中常用宏定义 一、Q_DECLARE_PRIVATE(Class) 二、Q_DECLARE_PRIVATE_D(Dptr, Class) 三、Q_DECLARE_PUBLIC(Class) 四、Q_D(Class) 和 Q_Q(Class)
一、Q_DECLARE_PRIVATE(Class)
# define Q_DECLARE_PRIVATE ( Class) inline Class##Private* d_func ( ) { # 此处的 d_ptr 是属于QObject类中的私有成员变量Q_CAST_IGNORE_ALIGN ( return reinterpret_cast < Class##Private * > ( qGetPtrHelper ( d_ptr) ) ; ) } inline const Class##Private* d_func ( ) const { Q_CAST_IGNORE_ALIGN ( return reinterpret_cast < const Class##Private * > ( qGetPtrHelper ( d_ptr) ) ; ) } friend class Class ##Private;
二、Q_DECLARE_PRIVATE_D(Dptr, Class)
# define Q_DECLARE_PRIVATE_D ( Dptr, Class) inline Class##Private* d_func ( ) { Q_CAST_IGNORE_ALIGN ( return reinterpret_cast < Class##Private * > ( qGetPtrHelper ( Dptr) ) ; ) } inline const Class##Private* d_func ( ) const { Q_CAST_IGNORE_ALIGN ( return reinterpret_cast < const Class##Private * > ( qGetPtrHelper ( Dptr) ) ; ) } friend class Class ##Private;
三、Q_DECLARE_PUBLIC(Class)
# define Q_DECLARE_PUBLIC ( Class) inline Class* q_func ( ) { return static_cast < Class * > ( q_ptr) ; } inline const Class* q_func ( ) const { return static_cast < const Class * > ( q_ptr) ; } friend class Class ;
四、Q_D(Class) 和 Q_Q(Class)
# define Q_D ( Class) Class## Private * const d = d_func ( )
# define Q_Q ( Class) Class * const q = q_func ( )