feat: v1.4.2 创建一个类 ExSwitchButton 和 ExSwitchButtonPrivate 类成功,解决了q_fun() 和 d_fun() 的编译不通过的问题

This commit is contained in:
touwoyimuli 2019-12-11 00:12:10 +08:00
parent 991ea349a5
commit 1565858861
4 changed files with 18 additions and 16 deletions

View File

@ -30,6 +30,8 @@
#include <QSlider> #include <QSlider>
#include <QScrollBar> #include <QScrollBar>
#include "MyWidget/ExSwitchButton.h"
EXWIDGET_USE_NAMESPACE EXWIDGET_USE_NAMESPACE
Example::Example(QWidget *parent) Example::Example(QWidget *parent)

View File

@ -20,8 +20,8 @@
* along with this program. If not, see <https://touwoyimuli.github.io/>. * along with this program. If not, see <https://touwoyimuli.github.io/>.
*/ */
#include "ExSwitchButton.h" #include "ExSwitchButton.h"
//#include "qglobal.h" #include "ExSwitchButton_p.h"
#include <QDebug>
EXWIDGET_BEGIN_NAMESPACE EXWIDGET_BEGIN_NAMESPACE
@ -29,7 +29,7 @@ EXWIDGET_BEGIN_NAMESPACE
/*! /*!
* \~chinese \brief ExSwitchButtonPrivate * \~chinese \brief ExSwitchButtonPrivate
*/ */
ExSwitchButtonPrivate::ExSwitchButtonPrivate(ExSwitchButton *qq) ExSwitchButtonPrivate::ExSwitchButtonPrivate(/*ExSwitchButton *qq*/)
{ {
} }
@ -48,11 +48,7 @@ void ExSwitchButtonPrivate::init()
q->setCheckable(true); q->setCheckable(true);
q->connect(q, SIGNAL(toggled(bool)), q, SLOT(onChange(bool))); q->connect(q, SIGNAL(toggled(bool)), q, SLOT(onChange(bool)));
} q->onChange(true);
ExSwitchButtonPrivate::ExSwitchButton()
{
} }
void ExSwitchButton::onChange(bool) void ExSwitchButton::onChange(bool)
@ -65,7 +61,4 @@ void ExSwitchButton::onChange(bool)
} }
EXWIDGET_END_NAMESPACE EXWIDGET_END_NAMESPACE

View File

@ -23,21 +23,24 @@
#define EXSWITCHBUTTON_H #define EXSWITCHBUTTON_H
#include "ExMyGlobal.h" #include "ExMyGlobal.h"
#include "ExSwitchButton_p.h" #include <QtGlobal>
#include <QAbstractButton> #include <QAbstractButton>
EXWIDGET_BEGIN_NAMESPACE EXWIDGET_BEGIN_NAMESPACE
class ExSwitchButtonPrivate; //Q_DECLARE_PRIVATE() 宏展开使用的
class ExSwitchButton : public QAbstractButton class ExSwitchButton : public QAbstractButton
{ {
Q_OBJECT
public: public:
explicit ExSwitchButton(); explicit ExSwitchButton();
~ExSwitchButton(); ~ExSwitchButton();
private slots: private slots:
void onChange(bool); void onChange(bool);
private:
Q_DECLARE_PRIVATE(ExSwitchButton)
}; };
EXWIDGET_END_NAMESPACE EXWIDGET_END_NAMESPACE

View File

@ -36,16 +36,20 @@ EXWIDGET_BEGIN_NAMESPACE
* \~chinese \sa Qt QPushButtonPrivate QPushButton * \~chinese \sa Qt QPushButtonPrivate QPushButton
*/ */
class ExSwitchButton;
class ExSwitchButtonPrivate : public QObjectPrivate { class ExSwitchButtonPrivate : public QObjectPrivate
{
public: public:
ExSwitchButtonPrivate(ExSwitchButton *qq); explicit ExSwitchButtonPrivate();
~ExSwitchButtonPrivate(); ~ExSwitchButtonPrivate();
void init(); void init();
public: public:
bool m_checked; //switch 是否处于开启状态 bool m_checked; //switch 是否处于开启状态
public:
Q_DECLARE_PUBLIC(ExSwitchButton) //要加上宏
}; };
EXWIDGET_END_NAMESPACE EXWIDGET_END_NAMESPACE