我想創建一個簡單的遊戲,使用計時器,但我似乎無法得到它的工作。它會拋出這個錯誤:「沒有匹配的函數調用'QObject :: connect(QTimer * &,const char *,Time * &,const char *)'」現在問題我做什麼我無法修復它請幫助。當我遇到這個錯誤時,我纔開始編寫遊戲。這裏是排除不重要(目前)qml文件的文件。QTimer基本程序幫助
Main.cpp的:
#include <QtGui/QApplication>
#include "qmlapplicationviewer.h"
#include "time.h"
#include <QObject>
#include <QTimer>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QmlApplicationViewer viewer;
viewer.setOrientation(QmlApplicationViewer::ScreenOrientationLockLandscape);
viewer.setMainQmlFile(QLatin1String("qml/RaakGame/main.qml"));
viewer.showExpanded();
Time *timmer = new Time;
QTimer *timer = new QTimer(0);
QObject::connect(timer, SIGNAL(timeout()), timmer, SLOT(ShowTime()));
timer->start(1000);
return app.exec();
}
time.h中:
#ifndef TIME_H
#define TIME_H
class Time
{
public:
Time();
private slots:
void ShowTime();
signals:
int setTime();
};
time.cpp:
#include "time.h"
int theTime = 60;
Time::Time()
{
ShowTime();
}
void Time::ShowTime()
{
theTime--;
}
int Time::setTime()
{
return theTime;
}
#endif // TIME_H