Results 1 to 2 of 2

Thread: Static timer attribute - undefined reference error

  1. #1
    Join Date
    Oct 2015
    Posts
    28
    Thanks
    10
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Static timer attribute - undefined reference error

    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:

    Qt Code:
    1. #ifndef INACTIVITYFILTER
    2. #define INACTIVITYFILTER
    3.  
    4. #include <QtCore/QCoreApplication>
    5. #include <QTimer>
    6. #include <QProcess>
    7.  
    8. namespace Ui {
    9. class InactivityFilter;
    10. }
    11.  
    12. class InactivityFilter : public QObject
    13. {
    14. Q_OBJECT
    15.  
    16. public:
    17. explicit InactivityFilter()
    18. {
    19. timer = new QTimer(this);
    20. timer->setSingleShot(true);
    21.  
    22. connect(timer, SIGNAL(timeout()), this, SLOT(showLogin()));
    23. resetTimer();
    24. }
    25.  
    26. bool eventFilter(QObject *obj, QEvent *ev)
    27. {
    28. if(ev->type() == QEvent::KeyPress ||
    29. ev->type() == QEvent::MouseMove)
    30. resetTimer();
    31.  
    32. return QObject::eventFilter(obj, ev);
    33. }
    34.  
    35. static void resetTimer()
    36. {
    37. timer->start(120000);
    38. }
    39.  
    40. static void stopTimer()
    41. {
    42. timer->stop();
    43. }
    44.  
    45. public slots:
    46. void showLogin()
    47. {
    48. qApp->quit();
    49. QProcess::startDetached(qApp->arguments()[0], qApp->arguments());
    50. }
    51.  
    52. private:
    53. static QTimer *timer;
    54. };
    55.  
    56. #endif // INACTIVITYFILTER
    To copy to clipboard, switch view to plain text mode 

    // Leutzig

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Static timer attribute - undefined reference error

    A static member of a C++ class needs to be defined in one of the compilation units additional to being declared in the class.

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    Leutzig (10th May 2016)

Similar Threads

  1. Undefined reference to qt-Lib after compiling qt static for amv7 under windows
    By michael_endres in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 23rd January 2014, 17:15
  2. Replies: 2
    Last Post: 11th August 2012, 17:37
  3. Undefined reference in static binding in Linux
    By gcubar in forum Installation and Deployment
    Replies: 9
    Last Post: 28th February 2011, 15:20
  4. error undefined reference ...............
    By amit_pansuria in forum Qt Programming
    Replies: 2
    Last Post: 8th June 2007, 14:28
  5. Undefined Reference error!!!
    By Kapil in forum Newbie
    Replies: 25
    Last Post: 28th March 2006, 12:03

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.