Hi,
I'm my application I have a class that sends the user back to the login page after 2 minutes of inactivity. On a specific page the application shouldn't go back to the login page, and therefore I've made a stopTimer() function, so this won't happen. To call this function without the need of using the InactivityFilter object created in main() I've made the timer static as well as stopTimer() and resetTimer(). This gives me a few of the following error:
/home/stud/FV/FlexVault/FlexVault_Qt/inactivityfilter.h:19: error: undefined reference to `InactivityFilter::timer'
Why is that?
How do I fix it?
Should I use signal and slots to call stopTimer() and resetTimer() from the page where I need to stop the timer?
My InactivityFilter is shown below:
#ifndef INACTIVITYFILTER
#define INACTIVITYFILTER
#include <QtCore/QCoreApplication>
#include <QTimer>
#include <QProcess>
namespace Ui {
class InactivityFilter;
}
class InactivityFilter
: public QObject{
Q_OBJECT
public:
explicit InactivityFilter()
{
timer->setSingleShot(true);
connect(timer, SIGNAL(timeout()), this, SLOT(showLogin()));
resetTimer();
}
{
if(ev
->type
() == QEvent::KeyPress ||
ev
->type
() == QEvent::MouseMove) resetTimer();
return QObject::eventFilter(obj, ev
);
}
static void resetTimer()
{
timer->start(120000);
}
static void stopTimer()
{
timer->stop();
}
public slots:
void showLogin()
{
qApp->quit();
QProcess::startDetached(qApp
->arguments
()[0], qApp
->arguments
());
}
private:
};
#endif // INACTIVITYFILTER
#ifndef INACTIVITYFILTER
#define INACTIVITYFILTER
#include <QtCore/QCoreApplication>
#include <QTimer>
#include <QProcess>
namespace Ui {
class InactivityFilter;
}
class InactivityFilter : public QObject
{
Q_OBJECT
public:
explicit InactivityFilter()
{
timer = new QTimer(this);
timer->setSingleShot(true);
connect(timer, SIGNAL(timeout()), this, SLOT(showLogin()));
resetTimer();
}
bool eventFilter(QObject *obj, QEvent *ev)
{
if(ev->type() == QEvent::KeyPress ||
ev->type() == QEvent::MouseMove)
resetTimer();
return QObject::eventFilter(obj, ev);
}
static void resetTimer()
{
timer->start(120000);
}
static void stopTimer()
{
timer->stop();
}
public slots:
void showLogin()
{
qApp->quit();
QProcess::startDetached(qApp->arguments()[0], qApp->arguments());
}
private:
static QTimer *timer;
};
#endif // INACTIVITYFILTER
To copy to clipboard, switch view to plain text mode
// Leutzig
Bookmarks