Hello,
I am trying to inherit QApplication in my code but unfortulately i am unable to connect with SLOTS,
I have commented the Q_OBJECT macro coz when i uncomment that macro it creates vtable problem to me.
Any idea about this problem please help.
.h file
#include <QtGui/QApplication>
#include <QtCore/QCoreApplication>
#include <QObject>
#include <QEvent>
#include <QTimer>
#include <QDebug>
{
// Q_OBJECT
public:
explicit InactivityWatcher(int &argc, char *argv[]);
public:
protected slots:
void appIdleForFiveSecs();
virtual bool event
(QEvent * e
);
};
#include <QtGui/QApplication>
#include <QtCore/QCoreApplication>
#include <QObject>
#include <QEvent>
#include <QTimer>
#include <QDebug>
class InactivityWatcher : public QApplication
{
// Q_OBJECT
public:
explicit InactivityWatcher(int &argc, char *argv[]);
public:
QTimer m_timer;
protected slots:
void appIdleForFiveSecs();
virtual bool notify(QObject *receiver, QEvent *event);
virtual bool event (QEvent * e);
};
To copy to clipboard, switch view to plain text mode
.cpp file
InactivityWatcher::InactivityWatcher(int &argc, char *argv[]):
{
// 3600000 => 30 minutes
m_timer.setInterval(10000);
connect(&m_timer, SIGNAL(timeout()), this, SLOT(appIdleForFiveSecs()), Qt::UniqueConnection);
m_timer.start();
}
void InactivityWatcher::appIdleForFiveSecs()
{
qDebug() << "Inactive ";
m_timer.stop();
}
{
if (event
->type
() == QEvent::MouseMove || event
->type
() == QEvent::KeyPress) { qDebug() << "Active";
m_timer.stop(); // reset timer
m_timer.start();
}
}
bool InactivityWatcher
::event(QEvent *e
) {
}
InactivityWatcher::InactivityWatcher(int &argc, char *argv[]):
QApplication(argc, argv)
{
// 3600000 => 30 minutes
m_timer.setInterval(10000);
connect(&m_timer, SIGNAL(timeout()), this, SLOT(appIdleForFiveSecs()), Qt::UniqueConnection);
m_timer.start();
}
void InactivityWatcher::appIdleForFiveSecs()
{
qDebug() << "Inactive ";
m_timer.stop();
}
bool InactivityWatcher::notify(QObject *receiver, QEvent *event)
{
if (event->type() == QEvent::MouseMove || event->type() == QEvent::KeyPress) {
qDebug() << "Active";
m_timer.stop(); // reset timer
m_timer.start();
}
return QApplication::notify(receiver, event);
}
bool InactivityWatcher::event(QEvent *e)
{
return QApplication::event(e);
}
To copy to clipboard, switch view to plain text mode
Bookmarks