PDA

View Full Version : Extending QTimer()



rishid
26th March 2008, 16:55
Hi,

I am trying to figure out how to extend the QTimer class so I can pass some variables through the timeout signal. Is that even possible? I was think I could like "catch" the normal timeout() emit and then just emit my own signal with some variables I need.

Or is there some other way I am do not know of to pass arguments or at least get the QTimer object from the signal() that comes through?

I have never done this before and pretty confused. :confused: Is what below anything similar to what it should be?

Thanks



#include <QTimer>
#include "common.h"


class FileTimer: public QTimer{

public:
FileTimer(QObject * parent, uint16 dest, QString fileName):
QTimer ( parent )
{
dest = dest;
fileName = fileName;
}

uint16 dest;
QString fileName;

signals:
void sendTimeout(uint16 dest, QString fileName);

void timeout()
{
emit QTimer::timeout();
emit sendTimeout(dest, fileName);
}
};

aamer4yu
26th March 2008, 19:18
May be QSignalMapper can be of some help to you.

A.H.M. Mahfuzur Rahman
7th August 2009, 01:45
But, after using a QSignalMapper how can I call a slot?
For example:

QTimer* timer = new QTimer(this);
signalMapper = new QSignalMapper(this); //signalMapper is private to the class

connect(timer,SIGNAL(timeout()),signalMapper,SLOT( map()));
signalMapper->setMapping(this,index);
connect(signalMapper,SIGNAL(mapped(int)),this,SIGN AL(timeout(int)));

But, now How Can I connect to a function say crossCapture(int)?

I tried connect(timer,SIGNAL(timeout()),this,crossCapture( int));
and
connect(timer,SIGNAL(timeout(int)),this,crossCaptu re(int));

None of them works ..

A.H.M. Mahfuzur Rahman
7th August 2009, 01:59
Sorry, My mistake:
It should be like this to work perfectly:

QTimer* timer = new QTimer(this);
signalMapper = new QSignalMapper(this); //signalMapper is private to the class

connect(timer,SIGNAL(timeout()),signalMapper,SLOT( map()));
signalMapper->setMapping(timer,index);
connect(signalMapper,SIGNAL(mapped(int)),this,SIGN AL(timeout(int)));

connect(this,SIGNAL(timeout(int)),this,SLOT(crossC apture(int)));

where timeout(int) is a signal of the current class.