Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. SOS:undefined reference to `vtable for<class name>

SOS:undefined reference to `vtable for<class name>

Scheduled Pinned Locked Moved Solved General and Desktop
26 Posts 6 Posters 10.0k Views
  • 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.
  • Q qazaq408
    15 Jun 2018, 04:46

    @qazaq408 said in SOS:undefined reference to `vtable for<class name>:

    @jsulm
    no,My class name "MocTest; and "MocTest" class inheriten QDialog
    and I write class declaration inthe .h file,wirte class definition in .cpp file

    .h file

    #ifndef DIALOG_H
    #define DIALOG_H
    
    #include <QDialog>
    
    class MocTest : public QDialog
    {
        Q_OBJECT
    
    public:
        MocTest(QWidget *parent = 0);
        ~MocTest();
    };
    
    #endif // DIALOG_H
    

    .cpp file

    #include "MocTest.h"
    
    MocTest::MocTest(QWidget *parent)
        : QDialog(parent)
    {
    }
    
    MocTest::~MocTest()
    {
    
    }
    
    J Offline
    J Offline
    J.Hilk
    Moderators
    wrote on 15 Jun 2018, 05:09 last edited by
    #17

    @qazaq408 said in SOS:undefined reference to `vtable for<class name>:
    somthing strange is going on, did you create the class files yourself? because the declaration guards are QtNorming conform and indicate file names of dialog.h and dialog.cpp

    #ifndef DIALOG_H
    #define DIALOG_H

    you didn't just write

    SOURCES += MocTest.cpp
    

    because you named your class MocTest, and the file itself is named dialog.cpp, right?

    Just made a basic test program and works fine, as expected:

    //*pro
    #-------------------------------------------------
    #
    # Project created by QtCreator 2018-06-15T07:01:09
    #
    #-------------------------------------------------
    
    QT       += core gui
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    TARGET = MocTest
    TEMPLATE = app
    
    # The following define makes your compiler emit warnings if you use
    # any feature of Qt which has been marked as deprecated (the exact warnings
    # depend on your compiler). Please consult the documentation of the
    # deprecated API in order to know how to port your code away from it.
    DEFINES += QT_DEPRECATED_WARNINGS
    
    # You can also make your code fail to compile if you use deprecated APIs.
    # In order to do so, uncomment the following line.
    # You can also select to disable deprecated APIs only up to a certain version of Qt.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    
    
    SOURCES += \
            main.cpp \
        moctest.cpp
    
    HEADERS += \
            mainwindow.h \
        moctest.h
    
    
    //main.cpp
    #include "moctest.h"
    #include <QApplication>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
    
        MocTest test;
        test.show();
        return a.exec();
    }
    
    
    //moctest.h
    #ifndef MOCTEST_H
    #define MOCTEST_H
    
    #include <QDialog>
    
    class MocTest : public QDialog
    {
        Q_OBJECT
    
    public:
        explicit MocTest(QDialog *parent = 0);
    };
    
    #endif // MOCTEST_H
    
    //MocTest.cpp
    #include "moctest.h"
    
    MocTest::MocTest(QDialog *parent) : QDialog(parent)
    {
    
    }
    
    

    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


    Q: What's that?
    A: It's blue light.
    Q: What does it do?
    A: It turns blue.

    Q 2 Replies Last reply 15 Jun 2018, 05:23
    1
    • J J.Hilk
      15 Jun 2018, 05:09

      @qazaq408 said in SOS:undefined reference to `vtable for<class name>:
      somthing strange is going on, did you create the class files yourself? because the declaration guards are QtNorming conform and indicate file names of dialog.h and dialog.cpp

      #ifndef DIALOG_H
      #define DIALOG_H

      you didn't just write

      SOURCES += MocTest.cpp
      

      because you named your class MocTest, and the file itself is named dialog.cpp, right?

      Just made a basic test program and works fine, as expected:

      //*pro
      #-------------------------------------------------
      #
      # Project created by QtCreator 2018-06-15T07:01:09
      #
      #-------------------------------------------------
      
      QT       += core gui
      
      greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
      
      TARGET = MocTest
      TEMPLATE = app
      
      # The following define makes your compiler emit warnings if you use
      # any feature of Qt which has been marked as deprecated (the exact warnings
      # depend on your compiler). Please consult the documentation of the
      # deprecated API in order to know how to port your code away from it.
      DEFINES += QT_DEPRECATED_WARNINGS
      
      # You can also make your code fail to compile if you use deprecated APIs.
      # In order to do so, uncomment the following line.
      # You can also select to disable deprecated APIs only up to a certain version of Qt.
      #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
      
      
      SOURCES += \
              main.cpp \
          moctest.cpp
      
      HEADERS += \
              mainwindow.h \
          moctest.h
      
      
      //main.cpp
      #include "moctest.h"
      #include <QApplication>
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
      
          MocTest test;
          test.show();
          return a.exec();
      }
      
      
      //moctest.h
      #ifndef MOCTEST_H
      #define MOCTEST_H
      
      #include <QDialog>
      
      class MocTest : public QDialog
      {
          Q_OBJECT
      
      public:
          explicit MocTest(QDialog *parent = 0);
      };
      
      #endif // MOCTEST_H
      
      //MocTest.cpp
      #include "moctest.h"
      
      MocTest::MocTest(QDialog *parent) : QDialog(parent)
      {
      
      }
      
      
      Q Offline
      Q Offline
      qazaq408
      wrote on 15 Jun 2018, 05:23 last edited by
      #18

      @J.Hilk
      I make a mistake when i reply...I'm in a hurry because my boss is kicking my ass....

      my class name "MocTest",it's inheriten QDialog,and "MocTest" class is writed in MocTest.h and MocTest,cpp

      A 1 Reply Last reply 15 Jun 2018, 05:52
      0
      • Q qazaq408
        15 Jun 2018, 05:23

        @J.Hilk
        I make a mistake when i reply...I'm in a hurry because my boss is kicking my ass....

        my class name "MocTest",it's inheriten QDialog,and "MocTest" class is writed in MocTest.h and MocTest,cpp

        A Offline
        A Offline
        aha_1980
        Lifetime Qt Champion
        wrote on 15 Jun 2018, 05:52 last edited by
        #19

        @qazaq408

        I have two suggestions for you:

        1. Create a completely new project from QtCreators wizards and see if you can compile it. Then add a dialog (also with the wizard) and see if it still works. If not, than something may be wrong with your setup.
        2. Upload your complete project somewhere so we can test it.

        Regards

        Qt has to stay free or it will die.

        1 Reply Last reply
        0
        • J J.Hilk
          15 Jun 2018, 05:09

          @qazaq408 said in SOS:undefined reference to `vtable for<class name>:
          somthing strange is going on, did you create the class files yourself? because the declaration guards are QtNorming conform and indicate file names of dialog.h and dialog.cpp

          #ifndef DIALOG_H
          #define DIALOG_H

          you didn't just write

          SOURCES += MocTest.cpp
          

          because you named your class MocTest, and the file itself is named dialog.cpp, right?

          Just made a basic test program and works fine, as expected:

          //*pro
          #-------------------------------------------------
          #
          # Project created by QtCreator 2018-06-15T07:01:09
          #
          #-------------------------------------------------
          
          QT       += core gui
          
          greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
          
          TARGET = MocTest
          TEMPLATE = app
          
          # The following define makes your compiler emit warnings if you use
          # any feature of Qt which has been marked as deprecated (the exact warnings
          # depend on your compiler). Please consult the documentation of the
          # deprecated API in order to know how to port your code away from it.
          DEFINES += QT_DEPRECATED_WARNINGS
          
          # You can also make your code fail to compile if you use deprecated APIs.
          # In order to do so, uncomment the following line.
          # You can also select to disable deprecated APIs only up to a certain version of Qt.
          #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
          
          
          SOURCES += \
                  main.cpp \
              moctest.cpp
          
          HEADERS += \
                  mainwindow.h \
              moctest.h
          
          
          //main.cpp
          #include "moctest.h"
          #include <QApplication>
          
          int main(int argc, char *argv[])
          {
              QApplication a(argc, argv);
          
              MocTest test;
              test.show();
              return a.exec();
          }
          
          
          //moctest.h
          #ifndef MOCTEST_H
          #define MOCTEST_H
          
          #include <QDialog>
          
          class MocTest : public QDialog
          {
              Q_OBJECT
          
          public:
              explicit MocTest(QDialog *parent = 0);
          };
          
          #endif // MOCTEST_H
          
          //MocTest.cpp
          #include "moctest.h"
          
          MocTest::MocTest(QDialog *parent) : QDialog(parent)
          {
          
          }
          
          
          Q Offline
          Q Offline
          qazaq408
          wrote on 15 Jun 2018, 05:53 last edited by
          #20

          @J.Hilk
          I guess that's is the point, MOC tools can't prduce moc*.cpp file
          alt text
          But I don't know why .
          the almost answer in google is that the encode of file is wrong,qt need utf-8,but i change the encode of .h file by vs and notepad++, it still don't work...

          A 1 Reply Last reply 15 Jun 2018, 05:55
          0
          • Q qazaq408
            15 Jun 2018, 05:53

            @J.Hilk
            I guess that's is the point, MOC tools can't prduce moc*.cpp file
            alt text
            But I don't know why .
            the almost answer in google is that the encode of file is wrong,qt need utf-8,but i change the encode of .h file by vs and notepad++, it still don't work...

            A Offline
            A Offline
            aha_1980
            Lifetime Qt Champion
            wrote on 15 Jun 2018, 05:55 last edited by aha_1980
            #21

            @qazaq408 said in SOS:undefined reference to `vtable for<class name>:

            I guess that's is the point, MOC tools can't prduce moc*.cpp file

            Then please do clean all build artefacts, and then compile your project. Paste the compile log here for analysis.

            PS: Also make sure that there are no Makefile, *.moc, *.o and other generated files in your source directory! This will lead to the strangest effects possible.

            Qt has to stay free or it will die.

            Q 1 Reply Last reply 15 Jun 2018, 06:14
            0
            • A aha_1980
              15 Jun 2018, 05:55

              @qazaq408 said in SOS:undefined reference to `vtable for<class name>:

              I guess that's is the point, MOC tools can't prduce moc*.cpp file

              Then please do clean all build artefacts, and then compile your project. Paste the compile log here for analysis.

              PS: Also make sure that there are no Makefile, *.moc, *.o and other generated files in your source directory! This will lead to the strangest effects possible.

              Q Offline
              Q Offline
              qazaq408
              wrote on 15 Jun 2018, 06:14 last edited by
              #22

              @aha_1980
              I had done this....
              even I cpoy these three file (Moctst.h,MocTest.cpp,Main.cpp) to another dir,like E:/tk

              and use cmd.exe
              /////
              e:
              cd ./tk
              moc MocTest.h -o Moc_MocTest.cpp

              the system tell me .E:\tk\MocTest.h:1: Note: No relevant classes found. No output generated....

              J 1 Reply Last reply 15 Jun 2018, 06:20
              0
              • Q qazaq408
                15 Jun 2018, 06:14

                @aha_1980
                I had done this....
                even I cpoy these three file (Moctst.h,MocTest.cpp,Main.cpp) to another dir,like E:/tk

                and use cmd.exe
                /////
                e:
                cd ./tk
                moc MocTest.h -o Moc_MocTest.cpp

                the system tell me .E:\tk\MocTest.h:1: Note: No relevant classes found. No output generated....

                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 15 Jun 2018, 06:20 last edited by
                #23

                @qazaq408 Don't copy anything, just create a new project and add there a new dialog and see whether it works.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                Q 1 Reply Last reply 15 Jun 2018, 06:30
                0
                • J jsulm
                  15 Jun 2018, 06:20

                  @qazaq408 Don't copy anything, just create a new project and add there a new dialog and see whether it works.

                  Q Offline
                  Q Offline
                  qazaq408
                  wrote on 15 Jun 2018, 06:30 last edited by JKSH
                  #24

                  @jsulm
                  if I create a new object that has a new dialog,(I don't revise anything and the class with Q_OBJECT marco),and make,
                  system tell me
                  alt text

                  and if i delete Q_OBJECT marco,it works ,but still has a question
                  alt text

                  J 1 Reply Last reply 15 Jun 2018, 07:17
                  0
                  • Q qazaq408
                    15 Jun 2018, 06:30

                    @jsulm
                    if I create a new object that has a new dialog,(I don't revise anything and the class with Q_OBJECT marco),and make,
                    system tell me
                    alt text

                    and if i delete Q_OBJECT marco,it works ,but still has a question
                    alt text

                    J Offline
                    J Offline
                    JKSH
                    Moderators
                    wrote on 15 Jun 2018, 07:17 last edited by
                    #25

                    @qazaq408

                    1. Restart your PC
                    2. Open Qt Creator
                    3. In the "Welcome" screen, click "Examples"
                    4. Search for the "Address Book Example"
                    5. Try to run this example

                    What do you see?

                    Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                    1 Reply Last reply
                    0
                    • Q Offline
                      Q Offline
                      qazaq408
                      wrote on 15 Jun 2018, 08:16 last edited by
                      #26

                      I take it...my company systm file are encrypted so that add some question when Qt produce .o file. I run win7 in the vritulBox and it's work!!!!!

                      Thank brother Chun,
                      Thank god
                      Thank everyone who help me or not,thank you cost so much time to answer my question.

                      thank you!!

                      1 Reply Last reply
                      2

                      26/26

                      15 Jun 2018, 08:16

                      • Login

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