我試圖運行QTimer
並讓它警告我時timeout
ing。爲此,我使用slot
和signal
來鏈接這兩個。錯誤與QObject :: connect()
的guy.h
:
#ifndef GUY_H
#define GUY_H
#include <QGraphicsItem>
#include <QTimer>
#include <QObject>
class Guy : public QGraphicsItem
{
public:
Guy(int x, int y);
void timerStart();
public slots:
void onTimeOutTimer();
[...]
QTimer *timer;
}
#endif // GUY_H
的guy.cpp
:
#include "guy.h"
#include <QTimer>
#include <QObject>
#include <stdio.h>
#include <iostream>
Guy::Guy(int x, int y)
{
timer = new QTimer();
}
void Guy::timerStart()
{
QObject::connect(timer, SIGNAL(timeout()), this, SLOT(onTimeOutTimer()));
this->timer->setInterval(1000);
this->timer->start();
std::cout << "starting timer" << std::endl;
}
void Guy::onTimeOutTimer()
{
std::cout << "check" << std::endl;
}
但作爲一個輸出中,我得到這個錯誤:
No matching function for call to 'QObject::connect(QTimer*&, const char*, Guy* const, const char*)'
正如我undertsand它是QTimer
沒有QObject
作爲th的第一個輸入e函數connect()
,但文檔指定QTimer
繼承自QObject
。 我不知道這裏。
信號和插槽只適用於QObject的子類,QGraphicsItem不是一個 – 2014-11-01 03:35:17