Hi. When I met the same problem I solved that with startTimer/killTimer and void timerEvent ( QTimerEvent * event ) reimplementation. Then what you can do is to set any Boolean variable (or QMutex based variable if you have multiple access) to true (lock) accordingly and process that inside timerEvent.
Typical solution might be:
static const int timeScale = 50; // 50 Msec
{
Q_OBJECT
public:
Q_INVOKABLE A
( QObject * parent
= 0 ) m_check(false),
m_timer(0)
{
m_timer = startTimer(timeScale);
}
~A()
{
if (m_timer > 0)
killTimer(m_timer);
}
public slots:
void handler()
{
if (m_check)
return;
// do something here
m_check = true;
}
protected:
{
if (m_check)
{
// do something
emit some_signal(some_args);
m_check != m_check; // Just quicker
}
}
private:
bool m_check;
int m_timer;
}
static const int timeScale = 50; // 50 Msec
class A: public QObject
{
Q_OBJECT
public:
Q_INVOKABLE A( QObject * parent = 0 )
: QObject(parent),
m_check(false),
m_timer(0)
{
m_timer = startTimer(timeScale);
}
~A()
{
if (m_timer > 0)
killTimer(m_timer);
}
public slots:
void handler()
{
if (m_check)
return;
// do something here
m_check = true;
}
protected:
void timerEvent ( QTimerEvent * event)
{
if (m_check)
{
// do something
emit some_signal(some_args);
m_check != m_check; // Just quicker
}
}
private:
bool m_check;
int m_timer;
}
To copy to clipboard, switch view to plain text mode
Good luck.
Bookmarks