diff --git a/QtCustomStyleEx/MyWidget/ExSwitchButton.cpp b/QtCustomStyleEx/MyWidget/ExSwitchButton.cpp index 162a0bd..45c3b3b 100644 --- a/QtCustomStyleEx/MyWidget/ExSwitchButton.cpp +++ b/QtCustomStyleEx/MyWidget/ExSwitchButton.cpp @@ -22,6 +22,7 @@ #include "ExSwitchButton.h" //#include "qglobal.h" + EXWIDGET_BEGIN_NAMESPACE //xxxPrivate class 会在 xxx.cpp 里面来实现 diff --git a/QtCustomStyleEx/MyWidget/ExSwitchButton.h b/QtCustomStyleEx/MyWidget/ExSwitchButton.h index 3fb9857..d2d3cd3 100644 --- a/QtCustomStyleEx/MyWidget/ExSwitchButton.h +++ b/QtCustomStyleEx/MyWidget/ExSwitchButton.h @@ -31,6 +31,7 @@ EXWIDGET_BEGIN_NAMESPACE class ExSwitchButton : public QAbstractButton { + Q_OBJECT public: explicit ExSwitchButton(); ~ExSwitchButton(); diff --git a/QtCustomStyleEx/MyWidget/ExSwitchButton_p.h b/QtCustomStyleEx/MyWidget/ExSwitchButton_p.h index 12b30a2..2c4ef74 100644 --- a/QtCustomStyleEx/MyWidget/ExSwitchButton_p.h +++ b/QtCustomStyleEx/MyWidget/ExSwitchButton_p.h @@ -24,18 +24,20 @@ #include "ExMyGlobal.h" #include +#include +#include EXWIDGET_BEGIN_NAMESPACE /*! * \~chinese \class ExSwitchButtonPrivate * \~chinese \brief ExSwitchButton 类的数据类, 便于实现源码/二进制兼容, 通常继承于 “自定义_Private” 的类 + * 若是自定义控件,没有继承于 QObjectPrivate 之类的, 使用 Q_Q Q_D 时候,会报错,需要自己定义 q_fun() 函数 * \~chinese \sa Qt 自带的 QPushButtonPrivate, QPushButton 实现 */ class ExSwitchButton; -class ExSwitchButtonPrivate //自定义控件通常继承于 QObjectPrivate 之类的 -{ +class ExSwitchButtonPrivate : public QObjectPrivate { public: ExSwitchButtonPrivate(ExSwitchButton *qq); ~ExSwitchButtonPrivate(); diff --git a/QtCustomStyleEx/QtCustomStyleEx.pro b/QtCustomStyleEx/QtCustomStyleEx.pro index d7ce2c4..eb5cd90 100644 --- a/QtCustomStyleEx/QtCustomStyleEx.pro +++ b/QtCustomStyleEx/QtCustomStyleEx.pro @@ -4,9 +4,10 @@ # #------------------------------------------------- -QT += core gui +#xxxPrivate 继承 Q-xxxx-Private的话,是需要的添加 core-private(有一些核心方法? 类 可能不开放) +QT += core gui core-private -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets widgets-private # 若是需要继承 widgets相关,需要添加 widgets-private TARGET = custom-style TEMPLATE = app