Я пытаюсь запустить 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
требуется в качестве первого ввода e function connect()
, но в документации указаны QTimer
наследуется от QObject
. У меня нет подсказки.
Сигнал и слоты работают только с подклассами QObject, QGraphicsItem не является одним –