问题:
Q_PRIVATE_SLOT的使用方法,我使用后报错如下,请指教:
moc_PrivateSlotTest.cpp(82,29): error C2027: 使用了未定义类型“PrivateSlotTestPrivate”
PrivateSlotTest.h(7): message : 参见“PrivateSlotTestPrivate”的声明
关键代码:
PrivateSlotTest.h
#ifndef _INCLUDE_PRIVATE_SLOT_TEST_H_
#define _INCLUDE_PRIVATE_SLOT_TEST_H_
#include <QObject>
#include "privateslottest_global.h"
class PrivateSlotTestPrivate;
class PRIVATESLOTTEST_EXPORT PrivateSlotTest : public QObject
{
Q_OBJECT
public:
PrivateSlotTest(QObject* parent = nullptr);
~PrivateSlotTest();
signals:
void TestSignal();
private:
QScopedPointer<PrivateSlotTestPrivate> const d_ptr;
Q_PRIVATE_SLOT(d_func(), void TestSlot())
Q_DECLARE_PRIVATE(PrivateSlotTest)
Q_DISABLE_COPY(PrivateSlotTest)
};
#endif // !_INCLUDE_PRIVATE_SLOT_TEST_H_
PrivateSlotTest.cpp
#include "PrivateSlotTest.h"
#include "PrivateSlotTest_h.h"
PrivateSlotTest::PrivateSlotTest(QObject* parent)
: QObject(parent)
, d_ptr(new PrivateSlotTestPrivate())
{
d_ptr->q_ptr = this;
}
PrivateSlotTest::~PrivateSlotTest()
{
}
#include "moc_PrivateSlotTest.cpp"
其他代码:
#include "PrivateSlotTest.h"
#ifndef _INCLUDE_TEMPLATE_H_H_
#define _INCLUDE_TEMPLATE_H_H_
#include <QObject>
#include <QLineEdit>
#include "PrivateSlotTest.h"
#include "TemplateClass.h"
class PrivateSlotTestPrivate : public TemplateClass<QLineEdit>
{
//Q_OBJECT
Q_DECLARE_PUBLIC(PrivateSlotTest)
public:
PrivateSlotTestPrivate();
~PrivateSlotTestPrivate();
void TestSlot();
private:
PrivateSlotTest* q_ptr = nullptr;
};
#endif // !_INCLUDE_TEMPLATE_H_H_
#include "PrivateSlotTest.cpp
#include "PrivateSlotTest_h.h"
PrivateSlotTestPrivate::PrivateSlotTestPrivate()
{
}
PrivateSlotTestPrivate::~PrivateSlotTestPrivate()
{
}
void PrivateSlotTestPrivate::TestSlot()
{
}
TemplateClass.h
#ifndef _INCLUDE_TEMPLATE_CLASS_H_
#define _INCLUDE_TEMPLATE_CLASS_H_
#include <list>
template<typename MemberClass>
class TemplateClass
{
public:
void AppendMember(MemberClass member)
{
m_members.push_back(member);
}
private:
std::list<MemberClass> m_members;
};
#endif // !_INCLUDE_TEMPLATE_CLASS_H_