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>
QtWS25 Last Chance

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 Offline
    Q Offline
    qazaq408
    wrote on 14 Jun 2018, 03:57 last edited by
    #1

    WIN7 + MingW32 + Qt5.7
    P1
    I build a custom class by Qt Creator.
    New File Or Project->choose Qt Widgets Application->->set name and son on(I belive you have done much times). Idon.t change any code and clicke "run",then QtCreator tell me "undefined reference to `vtable for<class name>"

    p2
    I delete macro "Q_OBJECT",and click "run",then the programme is running normal...
    P3
    I put a QPushButton on the dialog(Now the dialog without Q_OBJECT marco),and add the code like this

    connect(cancel_PushButton,SIGNAL(clicked()),this,SLOT(close()));
    

    I run the programme again ,and everything is OK,when I click "cancel" Button,the dialod is closed......You know ,this custom dialog(inheriten QDialog) haven't Q_OBJECT marco now.But it alose can use signals and slots....
    P3
    I add Q_OBJECT marco into custom dialog,and run the programme,the QtCreator tell me "undefined reference to `vtable for<class name>"....

    P4
    I delete Q_OBJECT marco again ,and put another QPushButton on dialog,and add a custom slots,the code look like this

    connect(test_PushButton,SIGNAL(clicked()),this,SLOT(myTest()));
    

    and when I compile , QtCreator tell me
    QObject::connect: No such slot QDialog::myTest() in ....
    but the programme still can run ,and when I click "cancel"pushButton,the programme is closed...

    P5
    For make custom slots(myTest()) work,I add Q_OBJECT marco again ,and when I run this pro ,Qt creator tell me undefined reference to `vtable for<class name>...

    By google,someont tell me delete moc file and qmake again.I delete all file besides .h and .cpp fie,but when I build the programme,Qt Creator still tell me undefined reference to `vtable for<class name>...

    anther one tell me when I put Q_OBJECT marco in the .cpp file ,it will lead to this ,but I write Q_OBJECT marco in the .h file..

    what can i do......

    J 1 Reply Last reply 14 Jun 2018, 04:18
    0
    • Q qazaq408
      14 Jun 2018, 03:57

      WIN7 + MingW32 + Qt5.7
      P1
      I build a custom class by Qt Creator.
      New File Or Project->choose Qt Widgets Application->->set name and son on(I belive you have done much times). Idon.t change any code and clicke "run",then QtCreator tell me "undefined reference to `vtable for<class name>"

      p2
      I delete macro "Q_OBJECT",and click "run",then the programme is running normal...
      P3
      I put a QPushButton on the dialog(Now the dialog without Q_OBJECT marco),and add the code like this

      connect(cancel_PushButton,SIGNAL(clicked()),this,SLOT(close()));
      

      I run the programme again ,and everything is OK,when I click "cancel" Button,the dialod is closed......You know ,this custom dialog(inheriten QDialog) haven't Q_OBJECT marco now.But it alose can use signals and slots....
      P3
      I add Q_OBJECT marco into custom dialog,and run the programme,the QtCreator tell me "undefined reference to `vtable for<class name>"....

      P4
      I delete Q_OBJECT marco again ,and put another QPushButton on dialog,and add a custom slots,the code look like this

      connect(test_PushButton,SIGNAL(clicked()),this,SLOT(myTest()));
      

      and when I compile , QtCreator tell me
      QObject::connect: No such slot QDialog::myTest() in ....
      but the programme still can run ,and when I click "cancel"pushButton,the programme is closed...

      P5
      For make custom slots(myTest()) work,I add Q_OBJECT marco again ,and when I run this pro ,Qt creator tell me undefined reference to `vtable for<class name>...

      By google,someont tell me delete moc file and qmake again.I delete all file besides .h and .cpp fie,but when I build the programme,Qt Creator still tell me undefined reference to `vtable for<class name>...

      anther one tell me when I put Q_OBJECT marco in the .cpp file ,it will lead to this ,but I write Q_OBJECT marco in the .h file..

      what can i do......

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 14 Jun 2018, 04:18 last edited by
      #2

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

      what can i do

      You can show us your code.
      Also, delete the build directory, run qmake and then build again.

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

      Q 2 Replies Last reply 14 Jun 2018, 04:42
      2
      • J jsulm
        14 Jun 2018, 04:18

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

        what can i do

        You can show us your code.
        Also, delete the build directory, run qmake and then build again.

        Q Offline
        Q Offline
        qazaq408
        wrote on 14 Jun 2018, 04:42 last edited by
        #3

        @jsulm
        .h file

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

        .cpp file

        #include "Dialog.h"
        
        Dialog::Dialog(QWidget *parent)
            : QDialog(parent)
        {
        }
        
        Dialog::~Dialog()
        {
        
        }
        

        main file

        #include "Dialog.h"
        #include <QApplication>
        
        int main(int argc, char *argv[])
        {
            QApplication a(argc, argv);
            Dialog w;
            w.show();
        
            return a.exec();
        }
        

        When I compile by Qt Creator ,it tell me undefined reference to `vtable for<class name>..

        Also, delete the build directory, run qmake and then build again.

        I had tried to do this... even I copy three file to another independent dir , but it still show undefined reference to `vtable for<class name>..

        1 Reply Last reply
        0
        • J jsulm
          14 Jun 2018, 04:18

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

          what can i do

          You can show us your code.
          Also, delete the build directory, run qmake and then build again.

          Q Offline
          Q Offline
          qazaq408
          wrote on 14 Jun 2018, 04:47 last edited by
          #4

          @jsulm
          If I delete Q_OBJECT marco,the programme can run,but QtCreator has a question

          "D:\vbox\untitled\Dialog.h:1: Note: No relevant classes found. No output generated."

          I can sure the encode is UTF-8

          J 1 Reply Last reply 14 Jun 2018, 05:02
          0
          • Q qazaq408
            14 Jun 2018, 04:47

            @jsulm
            If I delete Q_OBJECT marco,the programme can run,but QtCreator has a question

            "D:\vbox\untitled\Dialog.h:1: Note: No relevant classes found. No output generated."

            I can sure the encode is UTF-8

            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 14 Jun 2018, 05:02 last edited by
            #5

            @qazaq408 "New File Or Project->choose Qt Widgets Application" - I guess you mean "C++ class" not "Qt Widgets Application" or how did you add the dialog to your application?

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

            Q 1 Reply Last reply 14 Jun 2018, 05:05
            0
            • J jsulm
              14 Jun 2018, 05:02

              @qazaq408 "New File Or Project->choose Qt Widgets Application" - I guess you mean "C++ class" not "Qt Widgets Application" or how did you add the dialog to your application?

              Q Offline
              Q Offline
              qazaq408
              wrote on 14 Jun 2018, 05:05 last edited by
              #6

              @jsulm
              I can sure I choose Qt Widgets Application...and I also add dialog to my app
              if not ,it can't work (after delete Q_OBJECT marco).

              J 1 Reply Last reply 14 Jun 2018, 05:09
              0
              • Q qazaq408
                14 Jun 2018, 05:05

                @jsulm
                I can sure I choose Qt Widgets Application...and I also add dialog to my app
                if not ,it can't work (after delete Q_OBJECT marco).

                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 14 Jun 2018, 05:09 last edited by
                #7

                @qazaq408 But how did you add the Dialog class? Manually?

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

                Q 1 Reply Last reply 14 Jun 2018, 05:21
                0
                • J jsulm
                  14 Jun 2018, 05:09

                  @qazaq408 But how did you add the Dialog class? Manually?

                  Q Offline
                  Q Offline
                  qazaq408
                  wrote on 14 Jun 2018, 05:21 last edited by
                  #8

                  @jsulm
                  alt text
                  alt text
                  alt text
                  alt text

                  1 Reply Last reply
                  0
                  • Q Offline
                    Q Offline
                    qazaq408
                    wrote on 14 Jun 2018, 07:11 last edited by
                    #9

                    I'm only one who use Qt in my company.....
                    I cast two days on this queston and can't do anything..
                    My Boss Is angry ....
                    Who can help me.....

                    1 Reply Last reply
                    0
                    • V Offline
                      V Offline
                      VRonin
                      wrote on 14 Jun 2018, 07:15 last edited by
                      #10

                      Delete the build folder and re-run qmake. your code is fine

                      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                      ~Napoleon Bonaparte

                      On a crusade to banish setIndexWidget() from the holy land of Qt

                      1 Reply Last reply
                      5
                      • Q Offline
                        Q Offline
                        qazaq408
                        wrote on 15 Jun 2018, 01:20 last edited by
                        #11

                        I get more infomation by google...
                        I try puoduce Moc file by moc tools
                        moc doc.h -o Moc_doc.cpp
                        but system always tell me "F:\doc\Doc\Doc.h:1: Note: No relevant classes found. No output generated."
                        I change the encode of .h file by notepad++,whatever I use utf-8 or ansi,It doesn't work.
                        alt text

                        J 1 Reply Last reply 15 Jun 2018, 04:19
                        0
                        • Q qazaq408
                          15 Jun 2018, 01:20

                          I get more infomation by google...
                          I try puoduce Moc file by moc tools
                          moc doc.h -o Moc_doc.cpp
                          but system always tell me "F:\doc\Doc\Doc.h:1: Note: No relevant classes found. No output generated."
                          I change the encode of .h file by notepad++,whatever I use utf-8 or ansi,It doesn't work.
                          alt text

                          J Offline
                          J Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on 15 Jun 2018, 04:19 last edited by
                          #12

                          @qazaq408 Can you show your pro file?

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

                          Q 1 Reply Last reply 15 Jun 2018, 04:34
                          0
                          • J jsulm
                            15 Jun 2018, 04:19

                            @qazaq408 Can you show your pro file?

                            Q Offline
                            Q Offline
                            qazaq408
                            wrote on 15 Jun 2018, 04:34 last edited by
                            #13

                            @jsulm

                            #-------------------------------------------------
                            #
                            # Project created by QtCreator 2018-06-13T12:39:42
                            #
                            #-------------------------------------------------
                            
                            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 += \
                                    MocTest.h
                            

                            The .h and .cpp file one the 3th floor

                            J 1 Reply Last reply 15 Jun 2018, 04:36
                            0
                            • Q qazaq408
                              15 Jun 2018, 04:34

                              @jsulm

                              #-------------------------------------------------
                              #
                              # Project created by QtCreator 2018-06-13T12:39:42
                              #
                              #-------------------------------------------------
                              
                              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 += \
                                      MocTest.h
                              

                              The .h and .cpp file one the 3th floor

                              J Offline
                              J Offline
                              jsulm
                              Lifetime Qt Champion
                              wrote on 15 Jun 2018, 04:36 last edited by
                              #14

                              @qazaq408 Does MocTest.* contain your Dialog class?

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

                              Q 1 Reply Last reply 15 Jun 2018, 04:44
                              0
                              • J jsulm
                                15 Jun 2018, 04:36

                                @qazaq408 Does MocTest.* contain your Dialog class?

                                Q Offline
                                Q Offline
                                qazaq408
                                wrote on 15 Jun 2018, 04:44 last edited by
                                #15

                                @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 Dialog : public QDialog
                                {
                                    Q_OBJECT
                                
                                public:
                                    Dialog(QWidget *parent = 0);
                                    ~Dialog();
                                };
                                
                                #endif // DIALOG_H
                                

                                .cpp file

                                #include "Dialog.h"
                                
                                Dialog::Dialog(QWidget *parent)
                                    : QDialog(parent)
                                {
                                }
                                
                                Dialog::~Dialog()
                                {
                                
                                }
                                
                                Q 1 Reply Last reply 15 Jun 2018, 04:46
                                0
                                • Q qazaq408
                                  15 Jun 2018, 04:44

                                  @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 Dialog : public QDialog
                                  {
                                      Q_OBJECT
                                  
                                  public:
                                      Dialog(QWidget *parent = 0);
                                      ~Dialog();
                                  };
                                  
                                  #endif // DIALOG_H
                                  

                                  .cpp file

                                  #include "Dialog.h"
                                  
                                  Dialog::Dialog(QWidget *parent)
                                      : QDialog(parent)
                                  {
                                  }
                                  
                                  Dialog::~Dialog()
                                  {
                                  
                                  }
                                  
                                  Q Offline
                                  Q Offline
                                  qazaq408
                                  wrote on 15 Jun 2018, 04:46 last edited by
                                  #16

                                  @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.HilkJ 1 Reply Last reply 15 Jun 2018, 05:09
                                  0
                                  • 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.HilkJ Offline
                                    J.HilkJ 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.HilkJ 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

                                      aha_1980A 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

                                        aha_1980A Offline
                                        aha_1980A 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.HilkJ 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...

                                          aha_1980A 1 Reply Last reply 15 Jun 2018, 05:55
                                          0

                                          8/26

                                          14 Jun 2018, 05:21

                                          18 unread
                                          • Login

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