Hi everybody !
I have a strange problem this morning. I'm tryng to use a QTimer object in a class but it does not work.
I have a class which has a QTimer objet as a member. this class has also a slot to process each timer timeout.
I call a function to start the timer and check the return value of the function ... every thing is ok because the returned value is different from zero ... cool. I also check that there is no problem with the SIGNAL SLOT conection ... here again no problem. In fact there is a problem because the SLOT to process timer timeout is never called, why ?
My header file class is :
#include <qobject.h>
#include "HmiStateA.h"
#include "HmiState.h"
#include "Hmi.h"
#include <qtimer.h>
class CHmiStateB
: public QObject,
public CAvreHmiStateA
{
Q_OBJECT
public:
static CHmiState* GetInstance();
virtual ~CHmiStateB();
protected:
CHmiStateB();
static CHmiStateB* m_Instance;
public:
virtual void ShowHmi(CHmi*);
virtual void HideHmi(CHmi*);
virtual void ResetHmi(CHmi*);
virtual void ValidateHmiItem(CHmi*);
virtual void CancelHmiItem(CHmi*);
protected slots:
void ProcessTimerTimeout();
protected:
};
#endif
#include <qobject.h>
#include "HmiStateA.h"
#include "HmiState.h"
#include "Hmi.h"
#include <qtimer.h>
class CHmiStateB : public QObject, public CAvreHmiStateA
{
Q_OBJECT
public:
static CHmiState* GetInstance();
virtual ~CHmiStateB();
protected:
CHmiStateB();
static CHmiStateB* m_Instance;
public:
virtual void ShowHmi(CHmi*);
virtual void HideHmi(CHmi*);
virtual void ResetHmi(CHmi*);
virtual void ValidateHmiItem(CHmi*);
virtual void CancelHmiItem(CHmi*);
protected slots:
void ProcessTimerTimeout();
protected:
QTimer* pTimer;
};
#endif
To copy to clipboard, switch view to plain text mode
My implementation file class is :
#include "HmiStateB.h"
#include "HmiStateA.h"
#include <qapplication.h>
CHmiStateB* CHmiStateB::m_Instance = 0;
CHmiStateB::CHmiStateB():
CHmiStateA(),
pTimer(0)
{
if( !pTimer )
{
Q_ASSERT( pTimer );
connect(pTimer, SIGNAL(timeout()), this, SLOT(ProcessTimerTimeout()));
}
}
CHmiStateB::~CHmiStateB()
{
if( pTimer )
{
if( pTimer->isActive() )
pTimer->stop();
delete pTimer;
pTimer = 0;
}
}
CHmiState* CHmiStateB::GetInstance()
{
if( !m_Instance )
m_Instance = new CHmiStateB;
return m_Instance;
}
void CHmiStateB::ShowHmi(CHmi* hmi)
{
if( !pTimer->start(4000, TRUE) )
qDebug("Failed to start timer");
}
void CHmiStateB::HideHmi(CHmi* hmi)
{
if( pTimer->isActive() )
pTimer->stop();
}
void CHmiStateB::ResetHmi(CHmi* hmi)
{
}
void CHmiStateB::ValidateHmiItem(CHmi* hmi)
{
}
void CHmiStateB::CancelHmiItem(CHmi* hmi)
{
}
void CHmiStateB::ProcessTimerTimeout()
{
qDebug("Timer Timeout");
}
#include "HmiStateB.h"
#include "HmiStateA.h"
#include <qapplication.h>
CHmiStateB* CHmiStateB::m_Instance = 0;
CHmiStateB::CHmiStateB():
QObject(),
CHmiStateA(),
pTimer(0)
{
if( !pTimer )
{
pTimer = new QTimer;
Q_ASSERT( pTimer );
connect(pTimer, SIGNAL(timeout()), this, SLOT(ProcessTimerTimeout()));
}
}
CHmiStateB::~CHmiStateB()
{
if( pTimer )
{
if( pTimer->isActive() )
pTimer->stop();
delete pTimer;
pTimer = 0;
}
}
CHmiState* CHmiStateB::GetInstance()
{
if( !m_Instance )
m_Instance = new CHmiStateB;
return m_Instance;
}
void CHmiStateB::ShowHmi(CHmi* hmi)
{
if( !pTimer->start(4000, TRUE) )
qDebug("Failed to start timer");
}
void CHmiStateB::HideHmi(CHmi* hmi)
{
if( pTimer->isActive() )
pTimer->stop();
}
void CHmiStateB::ResetHmi(CHmi* hmi)
{
}
void CHmiStateB::ValidateHmiItem(CHmi* hmi)
{
}
void CHmiStateB::CancelHmiItem(CHmi* hmi)
{
}
void CHmiStateB::ProcessTimerTimeout()
{
qDebug("Timer Timeout");
}
To copy to clipboard, switch view to plain text mode
So if someone could tell what is wrong ?
Thanks in advance
Bookmarks