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
Qt Code:
  1. #include <QtGui/QApplication>
  2. #include <QtCore/QCoreApplication>
  3.  
  4. #include <QObject>
  5. #include <QEvent>
  6. #include <QTimer>
  7. #include <QDebug>
  8.  
  9. class InactivityWatcher : public QApplication
  10. {
  11. // Q_OBJECT
  12.  
  13. public:
  14. explicit InactivityWatcher(int &argc, char *argv[]);
  15.  
  16. public:
  17. QTimer m_timer;
  18.  
  19. protected slots:
  20. void appIdleForFiveSecs();
  21.  
  22. virtual bool notify(QObject *receiver, QEvent *event);
  23. virtual bool event (QEvent * e);
  24.  
  25. };
To copy to clipboard, switch view to plain text mode 

.cpp file
Qt Code:
  1. InactivityWatcher::InactivityWatcher(int &argc, char *argv[]):
  2. QApplication(argc, argv)
  3. {
  4. // 3600000 => 30 minutes
  5.  
  6. m_timer.setInterval(10000);
  7. connect(&m_timer, SIGNAL(timeout()), this, SLOT(appIdleForFiveSecs()), Qt::UniqueConnection);
  8.  
  9. m_timer.start();
  10. }
  11.  
  12. void InactivityWatcher::appIdleForFiveSecs()
  13. {
  14. qDebug() << "Inactive ";
  15. m_timer.stop();
  16. }
  17.  
  18. bool InactivityWatcher::notify(QObject *receiver, QEvent *event)
  19. {
  20. if (event->type() == QEvent::MouseMove || event->type() == QEvent::KeyPress) {
  21. qDebug() << "Active";
  22. m_timer.stop(); // reset timer
  23. m_timer.start();
  24. }
  25. return QApplication::notify(receiver, event);
  26. }
  27.  
  28. bool InactivityWatcher::event(QEvent *e)
  29. {
  30. return QApplication::event(e);
  31. }
To copy to clipboard, switch view to plain text mode