Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Undefined reference to `vtable for TestTimer'
Qt 6.11 is out! See what's new in the release blog

Undefined reference to `vtable for TestTimer'

Scheduled Pinned Locked Moved Qt Creator and other tools
11 Posts 3 Posters 7.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #2

    Here is the code with the good syntax. I'm sorry
    .

    @#include <QCoreApplication>
    #include <QTimer>
    #include <Qdebug> // pourquoi ??

    #include <stdio.h> // Pour printf

    //**************************************************
    class TestTimer : public QObject
    {
    Q_OBJECT //Macro qui sert à declarer et connecter les signals et slots
    // à mettre toujours meme si c'est superflu

    public:
    TestTimer(void) ;
    ~TestTimer(void);
    
    public:
        int Seconde;
        QTimer *Timer;
    
    
    public slots:
        void EveilTimer(void);
    

    };

    void TestTimer::EveilTimer(void)
    {
    Seconde++;
    printf("Seconde=%d\n",Seconde);
    }

    TestTimer::TestTimer(void)
    {
    Seconde = 0;
    Timer = new QTimer(this);
    connect (Timer,SIGNAL( timeout() ),this, SLOT( TestTimer::EveilTimer() ) );
    Timer->start(1000);
    }

    TestTimer::~TestTimer(void)
    {
    Timer->stop();
    delete Timer ;
    }
    //****************************************************
    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);

    TestTimer MonTimer;
    
    return a.exec&#40;&#41;;
    

    }
    @

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #3

      You probably forgot to include the header in your main file:
      @
      #include "testtimer.h"
      @

      Also, QObjects require the implementation to be in a separate file .cpp file (well, sort of. If you want to avoid problems, better stick to it :)).

      (Z(:^

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #4

        Hi,

        To add to sierdzio, if you add/remove Q_OBJECT you need to run qmake again before building

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #5

          It works if i have three files
          -TestTimer.h with the definition of the class
          _TestTimer.cpp with the code of the function in the class

          • main.cpp to invoqke the functions

          But i did not change anything else.

          Who can explain ??
          Thanks

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #6

            Here is the code with the good syntax. I'm sorry
            .

            @#include <QCoreApplication>
            #include <QTimer>
            #include <Qdebug> // pourquoi ??

            #include <stdio.h> // Pour printf

            //**************************************************
            class TestTimer : public QObject
            {
            Q_OBJECT //Macro qui sert à declarer et connecter les signals et slots
            // à mettre toujours meme si c'est superflu

            public:
            TestTimer(void) ;
            ~TestTimer(void);
            
            public:
                int Seconde;
                QTimer *Timer;
            
            
            public slots:
                void EveilTimer(void);
            

            };

            void TestTimer::EveilTimer(void)
            {
            Seconde++;
            printf("Seconde=%d\n",Seconde);
            }

            TestTimer::TestTimer(void)
            {
            Seconde = 0;
            Timer = new QTimer(this);
            connect (Timer,SIGNAL( timeout() ),this, SLOT( TestTimer::EveilTimer() ) );
            Timer->start(1000);
            }

            TestTimer::~TestTimer(void)
            {
            Timer->stop();
            delete Timer ;
            }
            //****************************************************
            int main(int argc, char *argv[])
            {
            QCoreApplication a(argc, argv);

            TestTimer MonTimer;
            
            return a.exec&#40;&#41;;
            

            }
            @

            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #7

              Here is the code with the good syntax. I'm sorry
              .

              @#include <QCoreApplication>
              #include <QTimer>
              #include <Qdebug> // pourquoi ??

              #include <stdio.h> // Pour printf

              //**************************************************
              class TestTimer : public QObject
              {
              Q_OBJECT //Macro qui sert à declarer et connecter les signals et slots
              // à mettre toujours meme si c'est superflu

              public:
              TestTimer(void) ;
              ~TestTimer(void);
              
              public:
                  int Seconde;
                  QTimer *Timer;
              
              
              public slots:
                  void EveilTimer(void);
              

              };

              void TestTimer::EveilTimer(void)
              {
              Seconde++;
              printf("Seconde=%d\n",Seconde);
              }

              TestTimer::TestTimer(void)
              {
              Seconde = 0;
              Timer = new QTimer(this);
              connect (Timer,SIGNAL( timeout() ),this, SLOT( TestTimer::EveilTimer() ) );
              Timer->start(1000);
              }

              TestTimer::~TestTimer(void)
              {
              Timer->stop();
              delete Timer ;
              }
              //****************************************************
              int main(int argc, char *argv[])
              {
              QCoreApplication a(argc, argv);

              TestTimer MonTimer;
              
              return a.exec&#40;&#41;;
              

              }
              @

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #8

                OK and thanks a lot. I did not knew that QOject required to be in a separated file and that running qmake first is better.

                My problem seems to be solved.

                1 Reply Last reply
                0
                • sierdzioS Offline
                  sierdzioS Offline
                  sierdzio
                  Moderators
                  wrote on last edited by
                  #9

                  Building of Qt applications includes not only invoking the compiler, but also several code generation tools (moc, uic, rcc). Those expect your code to follow certain conventions.

                  (Z(:^

                  1 Reply Last reply
                  0
                  • ? Offline
                    ? Offline
                    A Former User
                    wrote on last edited by
                    #10

                    Thanks you two.
                    I will not forget ! I have copied and stuck your answers as a comment in my code !! Now I am sure I will find others mistakes to do !!

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #11

                      Better avoid them, you'll have more time to code :)

                      Happy coding !

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt
                      • Unsolved