当前位置:网站首页>QT notes - Q_ Q and Q_ D learning

QT notes - Q_ Q and Q_ D learning

2022-07-26 03:14:00 Cool breeze in the old street °

In the source code , We will often see Q_Q and Q_D These two things , I'm curious , I went online to search for some and Checked some source code part

Q_D Related macro

#define Q_D(Class) Class##Private * const d = d_func()

Q_D(Test)
// After deployment   It's a   Pointer constants of private classes  
TestPrivate * const d = d_func();

d_func()

QScopedPointer<QPainterPathPrivate, QPainterPathPrivateDeleter> d_ptr;

QPainterPathData *d_func() const {
     return reinterpret_cast<QPainterPathData *>(d_ptr.data()); }

Q_DECLARE_PRIVATE(Class)

#define Q_DECLARE_PRIVATE(Class) \ inline Class##Private* d_func() \ {
       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(Test)
// After deployment 
 inline TestPrivate* d_func() {
    return reinterpret_cast<TestPrivate *>(qGetPtrHelper(d_ptr));}
 inline const TestPrivate* d_func() const{
    return reinterpret_cast<const TestPrivate *>(qGetPtrHelper(d_ptr));}
 friend class TestPrivate;

Q_Q Related macro

#define Q_Q(Class) Class * const q = q_func()

**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_DECLARE_PUBLIC(Test)  
    inline Test* q_func() {
     return static_cast<Test*>(q_ptr); } 
    inline const Test* q_func() const {
     return static_cast<const Test*>(q_ptr); } 
    friend class Test;
原网站

版权声明
本文为[Cool breeze in the old street °]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/207/202207260310053626.html