been_1990
24th October 2010, 19:50
I have a QObject subclass that sets a timer to call a slot. But that never happens.
shot.h:
#ifndef SHOT_H
#define SHOT_H
#include <QObject>
#include <QTimer>
class Shot : public QObject
{
Q_OBJECT
public:
explicit Shot(QObject *parent = 0);
private:
QTimer *timer;
public slots:
void updatePos();
};
#endif // SHOT_H
shot.cpp:
#include "shot.h"
#include <QDebug>
Shot::Shot(QObject *parent) :
QObject(parent)
{
timer = new QTimer();
connect(timer, SIGNAL(timeout()), this, SLOT(updatePos()));
timer->setInterval(0);
timer->start();
}
void Shot::updatePos()
{
//timer never reaches here...
}
shot.h:
#ifndef SHOT_H
#define SHOT_H
#include <QObject>
#include <QTimer>
class Shot : public QObject
{
Q_OBJECT
public:
explicit Shot(QObject *parent = 0);
private:
QTimer *timer;
public slots:
void updatePos();
};
#endif // SHOT_H
shot.cpp:
#include "shot.h"
#include <QDebug>
Shot::Shot(QObject *parent) :
QObject(parent)
{
timer = new QTimer();
connect(timer, SIGNAL(timeout()), this, SLOT(updatePos()));
timer->setInterval(0);
timer->start();
}
void Shot::updatePos()
{
//timer never reaches here...
}