[Interest] subclassed QTimer

Frank Hemer frank at hemer.org
Tue Nov 3 14:20:33 CET 2015


Hi René,

On Tuesday 03 November 2015 14:13:46 René J.V. Bertin wrote:
> Hi,
> 
> I wanted to add a quick timer to an editor class to check the state of the
> various items that editor can handle. It'd be cumbersome to subclass the
> edit items to add a timeout slot to them, or to extend the editor class so
> a timeout slot would get called with the appropriate item. The easiest way
> seemed to be to subclass QTimer:
> 
> class QItemTimer : public QTimer {
> public:
> 	QItemTimer(QObject *parent, Item *item)
> 
> 		: QTimer(parent)
> 
> 	{
> 		_item = item;
> 	}
> public slots:
> 	void fired();
> protected:
> 	Item *_item;
> };
> 
> and then do
> 
> 	QItemTimer *t = new QItemTimer(0, _item);
> 	connect(t, SIGNAL(timeout()), t, SLOT(fired()));
> 	t->start(1000);
> 	timerList.append(t);
> 
> but as far as I can tell my fired slot isn't being called.
> 
> I'm probably overlooking something obvious?

I'm missing the Q_OBJECT macro

Frank



More information about the Interest mailing list