I'm trying to create a simple game that uses a timer but I can't seem to get it working. It throws this error: "no matching function for call to 'QObject::connect(QTimer*&, const char*, Time*&, const char*)'" now matter what I do do I can't fix it please help. I have only just started coding the game when I ran into this error. Here are the files exluding the unimportant(at the moment) qml file.
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:
Ti开发者_开发技巧me();
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
Your implementation of Time does not declare it to be a QObject, so you can't not connect slots or signals from it. You need to inherit from QObject (or probably QWidget if you want to draw on the screen) and then include the statement Q_OBJECT
which instantiates a few needed things.
class Time : public QWidget
{
Q_OBJECT
public:
Time();
private slots:
void ShowTime();
signals:
int setTime();
};
I notice that your classes do not contain the Q_OBJECT
macro defined. This may help your efforts.
class Time
{
Q_OBJECT
public Time()
.
.
.
}
精彩评论