我想创建一个Qt接口,强制任何子类实现两个主要方法集和获取标题.但是当我尝试编译它时,我得到一个奇怪的错误消息,说明了一些关于qt_check_for_QOBJECT_macro和staticMetaObject的信息.在mainwindow.cpp中,我必须将任何页面转换为接口,以便依赖getter和setter方法.我没有看到任何其他方式来做到这一点.
这是我的代码:
//IPage.h
#ifndef IPAGE_H
#define IPAGE_H
#include <QString>
class IPage
{
public:
virtual QString title()=0;
virtual void setTitle(QString t)=0;
};
#endif // IPAGE_H
//buildings.h:
#ifndef BUILDINGS_H
#define BUILDINGS_H
#include "IPage.h"
#include <QDialog>
class Buildings : public IPage, public QDialog
{
Q_OBJECT
private:
QString m_title;
//stuff...
};
#endif
//buildings.cpp
//stuff...
void Buildings::setTitle(QString t)
{
m_title = t;
setWindowTitle(t);
}
QString Buildings::title()
{
return m_title;
}
//mainwindow.cpp:
QMdiSubWindow *MainWindow::findChild(const QString &title)
{
foreach (QMdiSubWindow *window, mdiArea->subWindowList()) {
IPage *child = qobject_cast<IPage …Run Code Online (Sandbox Code Playgroud) qt ×1