我有一個簡單的類,當我的程序獲得並失去焦點時停止並啓動一個計時器,但它給出的錯誤是QObject是MyApp在每個信號插槽連接上的模糊基礎。 下面是相關代碼:QObject繼承不明確的基地
class MyApp : public QApplication, public QObject
{
Q_OBJECT
...
}
這裏是我的(凌亂)Main.cpp的:
#include <QtGui/QApplication>
#include "qmlapplicationviewer.h"
#include <QObject>
#include <QGraphicsObject>
#include <QTimer>
#include <QVariant>
#include "timecontrol.h"
#include "scorecontrol.h"
#include "Retry.h"
#include <QEvent>
#include "myapp.h"
int main(int argc, char *argv[])
{
MyApp app(argc, argv);
QmlApplicationViewer viewer;
viewer.setOrientation(QmlApplicationViewer::ScreenOrientationLockLandscape);
viewer.setMainQmlFile(QLatin1String("qml/Raker/main.qml"));
viewer.showExpanded();
QObject *rootObject = viewer.rootObject();
QTimer *timmer = new QTimer;
timmer->setInterval(1000);
TimeControl *timcon = new TimeControl;
scorecontrol *scorer = new scorecontrol;
Retry *probeer = new Retry;
QObject::connect(timmer, SIGNAL(timeout()), timcon, SLOT(updateTime()));
QObject::connect(timcon, SIGNAL(setTime(QVariant)), rootObject, SLOT(setTime(QVariant)));
QObject::connect(rootObject, SIGNAL(blockClicked(int, int)), scorer, SLOT(checkRight(int, int)));
QObject::connect(scorer, SIGNAL(setScore(QVariant)), rootObject, SLOT(setScore(QVariant)));
QObject::connect(scorer, SIGNAL(setState(QVariant)), rootObject, SLOT(setState(QVariant)));
QObject::connect(rootObject, SIGNAL(start()), probeer, SLOT(Reetry()));
QObject::connect(probeer, SIGNAL(start()), timmer, SLOT(start()));
QObject::connect(probeer, SIGNAL(stop()), timmer, SLOT(stop()));
QObject::connect(probeer, SIGNAL(start(int)), scorer, SLOT(randomNum(int)));
QObject::connect(probeer, SIGNAL(sReset()), timcon, SLOT(reset()));
QObject::connect(probeer, SIGNAL(tReset()), scorer, SLOT(reset()));
QObject::connect(timcon, SIGNAL(timeOut()), scorer, SLOT(reset()));
QObject::connect(timcon, SIGNAL(setState(QVariant)), rootObject, SLOT(setState(QVariant)));
QObject::connect(timcon, SIGNAL(changeFinal()), scorer, SLOT(changeFinal()));
QObject::connect(scorer, SIGNAL(setFinal(QVariant)), rootObject, SLOT(setFinal(QVariant)));
QObject::connect(&app, SIGNAL(focusL()), probeer, SLOT(focusL()));
QObject::connect(&app, SIGNAL(focusG()), probeer, SLOT(focusG()));
return app.exec();
}
MyApp.cpp中:
#include "myapp.h"
#include <QDebug>
#include <QObject>
MyApp::MyApp(int argc, char **argv): QApplication(argc, argv)
{
installEventFilter(this);
}
bool MyApp::eventFilter(QObject *object, QEvent *event)
{
if (event->type() == QEvent::ApplicationDeactivate)
{
qDebug() << "Focus lost";
focusL();
}
if (event->type() == QEvent::ApplicationActivate)
{
qDebug() << "Focus gained";
focusG();
}
return false;
}
好吧,但是現在在Q_OBJECT宏上方的「{」上以及MyApp.cpp中這兩行上MyApp的兩次出現中獲得對'MyApp'的vtable的未定義引用:「MyApp :: MyApp(int argc,char ** argv):QApplication(argc,argv)」 – Gerharddc
你的'main()'看起來像什麼? ...我也會首先在你的項目上再次發表Laurent關於運行'qmake'的評論。 – Jason
我已將我的主添加到我的qeustion中 – Gerharddc