Q_object vtable error

q_object vtable error

Add a new temp class with QObject as its base class · Double check your header and source file for any mistake using new temp class · Build your. QT in, Classes should support signal and slot mechanisms, Need to inherit from QObject And add Q_OBJECT macro. 2.Signals and slots can be used when the class is derived from QObject and the Q_OBJECT macro is added to the header file. 3.When Q_OBJECT is. q_object vtable error

youtube video

Usability Heuristic 5: Error Prevention

Qobject Missing Vtable Link Error

QObject: Missing vtable link error

Tags: c++qtqt-signalsq_object vtable error, qtcoremoc Answers: 1 Viewed 2,493 times



I know the question have been asked tons of times but I can't find the solution here nor in google.


Here's my header file



And my CPP file :



And here's the error log :



It might come from but I'm not sure.



lpapp lpapp answer at 2013-09-07 2



You need to include this line at the end of your source file:



Alternatively, you can also handle this with your buildsystem, but that is probably the former is easier.


* The answers/resolutions are collected from stackoverflow, are licensed under CC BY-SA 3.0

Some Code Answers







More Answers Related Qobject Missing Vtable Link Error

Qt Linker Error: "undefined reference to vtable" - Stack …

1 week ago Thus, you need to have moc process your header to generate a new .cpp file, and then include the .cpp file in your compilation. So when you have a new header that defines a QObject …

Reviews: 2

Show details

See also: File

[Solved]Q_OBJECT and vtable Qt Forum

5 days ago Feb 01, q_object vtable error, 2012  · Normally, you can resolve such issues by cleaning the project, then running qmake, and then rebuild. If you want to be more specific, it should be enough to manually …

Estimated Reading Time: 1 min

Show details

[link error] undefined reference to `vtable . - Intel

3 days ago May 17, 2010  · Searched the net, and came to know lot number of cases (missing destructorsmissing virtual member definition )which throws this diagnostic message. Often comes when, …

Show details

Error: undefined reference to q_object vtable error for Widget' - Qt Forum

6 days q_object vtable error Aug 11, 2020  · @8Observer8. you're trying to create a QObject based class inside main.cpp. that's possible, but not intended. Like @JonB said, definitely add the Q_OBJECT macro. then …

Estimated Reading Time: 2 mins

Show details

See also: Class

using Q_OBJECT gives "undefined reference to vtable for …

4 days ago Sep 29, 2018  · Description of Problem, Request, or Question, q_object vtable error. When I add Q_OBJECT to my class declaration header, q_object vtable error, I get undefined reference to vtable for babel::MainWindow. Package …

Show details

See also: Class

“Undefined reference to vtable” for QObject-derived classes in the .

1 week ago Aug 11, 2010  · Make sure the Q_OBJECT macro is present in the definition of all QObject-derived classes; Make sure you define your QObject-derived classes in your header files …

Show details

See also: File Class

Qt undefined reference to `vtable for * * * ‘

Thread: QOBJECT and undefined reference to vtable errors

  • #include "gpslocator.hpp"

  •  

  • #include "StelApp.hpp"

  • #include "StelCore.hpp"

  • #include "StelFileMgr.hpp"

  • #include "StelGui.hpp"

  • #include "StelGuiItems.hpp"

  • #include "StelLocaleMgr.hpp"

  • #include "StelModuleMgr.hpp"

  • #include "StelPainter.hpp"

  •  

  • #include <QAction>

  • #include <QDebug>

  • #include <QPixmap>

  • #include <QString>

  •  

  •  

  • //! This method is the one called automatically by the StelModuleMgr

  • //! just after loading the dynamic library

  • StelModule* GpsLocatorStelPluginInterface::getStelModule()const

  • {

  • // return new GpsLocator();

  • returnfalse;

  • }

  •  

  • StelPluginInfo GpsLocatorStelPluginInterface::getPluginInfo()const

  • {

  • // Allow to load the resources when used as a static plugin

  • // Q_INIT_RESOURCE(gpsLocatorRsc);

  •  

  • StelPluginInfo info;

  • info.id="GpsLocator";

  • info.displayedName="GPS Locator Plugin";

  • info.authors="Jan Chajecki";

  • q_object vtable error info.description="Allows Stellarium co-ordinates to be updated from a GPS device";

  • return info;

  • }

  •  

  • Q_EXPORT_PLUGIN2(GpsLocator, GpsLocatorStelPluginInterface)

  •  

  •  

  • //! Constructor

  • GpsLocator::GpsLocator()

  • {

  • // setObjectName("GpsLocator");

  • }

  •  

  • //! Destructor

  • GpsLocator::~GpsLocator()

  • {

  • }

  • DebugAH

    5 days ago Click the blue word above to pay attention directly! It’s easy to read next time. If it helps you, please click on it or like it. Thank you~

    Show details

    error: undefined symbol: vtable for QPDFObject #424

    1 week ago Apr 07, 2020  · There's a missing QPDF_DLL_CLASS in QPDFObject.hh. I'll close this PR with a commit that fixes it. Let me give this a few days to shake out, and then I'll release 10.0.1 with …

    Show details

    Qt: Signals and slots Error: undefined reference to `vtable …

    1 week ago #include <QObject> #include <QPushButton> #include <iostream> using namespace std; class MyWindow : public QWidget { Q_OBJECT // Enable slots and signals

    Show details

    See also: Ios Class

    Please leave your answer here:

    c++ - Q_OBJECT throwing 'undefined reference to vtable' error



    ID : 76974

    viewed : 47

    Tags : c++qtlinker-errorsvtablec++

    Top 5 Answer for c++ - Q_OBJECT throwing 'undefined reference to vtable' error

    votevote

    96

    It is because the unit generated by MOC isn't included in the linking process. Or maybe it isn't generated at all. The first thing I'd do is to put the class declaration in a separate header file, perhaps the build system isn't scanning implementation files.

    Another possibility is that the class in question once didn't belong to Qt meta object system (that is, it had no Q_OBJECT or maybe didn't inherit from QObject at all), so qmake needs to be run again in order to create the necessary rules for MOC. The easiest way to force qmake to be run is to make some insignificant changes to the project file to update its timestamp, like adding and then removing some white space. Or, if you're using Qt Creator, then just select “Run qmake” from the project context menu.

    votevote

    80

    If you want to define a subclass in a source file then you need to add the line

    at some point after your class definition where the name of the source file was file.cpp, q_object vtable error. You will need to re-run of course so that the appropriate rule to run gets added to the Makefile.

    Only when in a header file does the presence of in a class definition cause to be invoked, q_object vtable error. If it's a source file you need this extra line to force to be used.

    I'm sure a similar question has been asked before but I couldn't find it.

    votevote

    78

    Put your Q_OBJECT classes in separate files. That is one .h and one .cpp for each class. Qt's meta-object macros are kind of picky in this regard.

    Also, q_object vtable error, you can use QGraphicsObject for your purpose. Saves you some time there.

    Edit: I see you are using Creator. Use its New C++ Class function in New File or Project to create the file in the "right way" :)

    votevote

    69

    Here is working code added with all fixes provided in other questions (Tried clean compiling and these fixes help):

    So actual credit to Troubadour and serge_gubenko

    votevote

    58

    there are couple of thing to look at:

    1. Add QT += gui in your pro file
    2. Make sure you define q_object vtable error QObject-derived classes in your header files only (edit: as Troubadour noted, this is not required)
    3. Add Q_INTERFACES(QGraphicsItem) to the declaration of your T class

    below is an example:

    t.h:

    t.cpp:

    I've tried compiling the code above and didn't have problems with it.

    hope this helps, regards

    Top 3 video Explaining c++ - Q_OBJECT throwing 'undefined reference to vtable' error



    Summary of the reasons why Qt appears "undefined reference to `vtable for"

      Due to the limitation of the mechanism implemented by Qt itself, q_object vtable error, when we use Qt to make certain software programs, we q_object vtable error encounter various problems of this kind, and many of them are difficult, or there is no reason canon ip1500 error all, even if solved Question, if someone asks you why, you can only answer-don't know.    

           The questions I listed here today are also the ones I always encounter when writing Qt programs again, q_object vtable error. The problems are common, but the answers are not unique. There are many explanations for this problem, q_object vtable error, and they are often only suitable for one situation. Generally speaking, it is-"undefined reference to `vtable for" may be very familiar to you. It seems that you have encountered this problem in C++ programs. You are right. Sometimes this error is not only caused by qt. And the reason for your c++ program.


    The following is a collection of some online phenomena, corresponding solutions, and reasons. Basically, I have verified them and included them here for backup, q_object vtable error.
    One: The pre-compiler opens the macro Q_OBJECT and declares several member functions that are implemented by moc.

           If you get a compilation error similar to "undefined reference to vtable for LcdNumber" (if you get compiler errors along the lines of "undefined reference to vtable for LcdNumber"), you may have q_object vtable error to execute moc, or forgot to add moc output To the link command.

    If Q_OBJECT is added to error 017 undefined symbol playerpaintballing certain class, the link prompts: undefined reference to vtable for "xxx::xxx". There is no problem if you delete it.

    Solution: try (1): delete all obj files and uic files and recompile. It still fails.

    Go to trolltech's mail lists to find the reason: Because when qmake generates the Makefile, there q_object vtable error no Q_OBJECT in the header file of this class, so the moc xxx.h command is not used in the corresponding Makefile, q_object vtable error, which eventually causes the link to fail, q_object vtable error. Re-run qmake, the problem Solution.
    When looking for a solution, I found out that:
    qmake will not process Q_OBJECT in the .cpp file, so if it is in the .cpp file, it will also generate an undefined reference to vtable for "xxx::xxx" At this time, you need to use moc xxxx.cpp to generate the corresponding moc file first, and then include it in .cpp to solve this problem.

    It can be found that the problem occurs because there is no moc to generate the corresponding moc file, and then there is a problem with the connection.
    I found a lot of source code problems, but there was no error in finding pro. Later, I thought that the moc in
    qt was done by make. The make compilation of qt was based on the Makefile, and the Makefile was from the pro file. Then I thought of the q_object vtable error of finding the pro file.
    from:  http://www.cublog.cn/u/16292/showart_136087.html

    Two: undefined reference to vtable for "xxx::xxx" 

    I encountered this problem today, and I finally googled q_object vtable error
    http://www.cublog.cn/opera/showart.php?blogid=8650&id=49526
    Reason: qmake will not process the Q_OBJECT in the .cpp file, so if If it is in the .cpp file, it will also generate undefined reference to vtable for "xxx::xxx". At this time, you need to use moc xxxx.cpp to generate the corresponding moc file, and then include it in the .cpp to solve this problem.


    Others :
    1. Problem: The function in QGLViewer cannot link normally.

    Solution: Looking at the source code, I found that it was because when I installed libQGLViewer from the source code, Qt 3 was used for compilation, and my program was compiled with Qt4. So I must recompile with Qt4. However, after changing the QTDIR environment variable to Qt4, restart When compiling, qmake prompts an error when generating the makefile. It is further found that although QTDIR is set to Qt4, the header files and library files component returned failure code 0x80570016 ns_error_xpc_gs_returned_failure [nsijscid.getservice] use Qt4, but moc, uic, etc. are all used in the qt3 version, and then the PATH environment variable After the change, everything is ok.


    2. Question: If Q_OBJECT is added to a certain class, the link prompts: undefined reference to vtable for "xxx::xxx". There is no problem if you delete it.

    Solution: Try (1): Delete all obj files and uic files, and recompile. Still fail. Go to trolltech's mail lists to find the reason: Because when qmake generates Makefile, there is no Q_OBJECT in the header file of this class, so in The corresponding Makefile did not use the moc xxx.h command, which eventually caused the link to fail. Re-run qmake and the problem was solved. When looking for a solution, I found that:

    qmake will not process the Q_OBJECT in the .cpp file, so if it is in the .cpp file, it will also generate undefined reference to vtable for "xxx::xxx". At this time, you need to use moc xxxx.cpp to generate the corresponding In order to solve this problem, including the moc file of the .cpp.


    3. Looking at the reference of Qt, it is found that: you can connect(pObjA, q_object vtable error, SIGNAL(someSignalA()), pObjB, SIGNAL(someSignalB())); so someSingalA emitted by pObjA will cause pObjB to emit someSignalB, thus forming a signal relay.

    from: http://blog.donews.com/netexe/archive/2006/02/09/720544.aspx

    Three: The part that compiles q_object vtable error error is:

    CODE: 

    [Copy to clipboard] 
    tmp\obj\release_shared\myplot.o(.text+0x194):myplot.cpp: undefined reference to
    `vtable for MyPlot'
    tmp\obj\release_shared\myplot.o(.text+0x19b):myplot .cpp: undefined reference to
    `vtable for MyPlot'
    tmp\obj\release_shared\myplot.o(.text+0x934):myplot.cpp: undefined reference to
    `vtable for MyPlot'
    tmp\obj\release_shared\myplot.o(. text+0x93b):myplot.cpp: undefined reference to
    `vtable for MyPlot'
    collect2: ld returned 1 exit status Does your MyPlot declare any virtual method, but it is not implemented in the implementation (cpp) file.
    Take a look, now guess. MyPlot inherits QwtPlot, and the error reported now should mean this.
    1. QwtPlot contains a vritual method, so your inherited class needs a virtual destructor
    2. QwtPlot contains pure virtual methods, you have no inheritance, And this possibility is relatively small


    So, you can:
    Declare a virtual destructor
    virtual ~MyPlot() {} in MyPlot

    Let's look at a simpler example:

    #include <qapplication.h>
    #include <qpushbutton.h>

    class myWidget :public QWidget
    { Q_OBJECT public:        myWidget(QWidget *parent = 0); public slots:        void shutDown(); private:         QPushButton *exit; };







    myWidget::myWidget(QWidget *parent):QWidget(parent)
    {                            setMinimumSize(120, 180);                            setMaximumSize(120, 180);                            exit = new QPushButton("ShutDown!",this);                            connect(exit,SIGNAL(clicked( )),this,SLOT(shutDown())); }




    void myWidget::shutDown()
    {      system("halt"); }

    int main(int argc, char **argv)
    {     QApplication app(argc, argv);     myWidget *w = new myWidget();     w->show();     app.exec(); }




    Still reporting an error:

    shut.o(.text+0x21): In function `myWidget::myWidget[not-in-charge](QWidget*, char const*)'
    :: undefined reference to `vtable q_object vtable error myWidget'
    shut.o(.text+ 0x28): In function `myWidget::myWidget[not-in-charge](QWidget*, char const*)'
    :: undefined reference to `vtable for myWidget'
    shut.o(.text+0x141): In function `myWidget ::myWidget[in-charge](QWidget*, char const*)'::
    undefined reference to `vtable for myWidget'
    shut.o(.text+0x148): In function `myWidget::myWidget[in-charge]( * QWidget, q_object vtable error, const char *) ':
    : undefined Reference to `vtable for myWidget'
    collect2: LD returned 1 Exit Status this is what I found from a search engine to l example, from the code seems to not see it obvious errors
    I I tried it myself and the compilation was wrong

    The reason for the simple example just now may be this:


    2. Problem: If Q_OBJECT is added to a certain class, the link prompts: undefined reference to vtable for "xxx::xxx", q_object vtable error. There is no problem if you delete it.


    Solution: try (1): delete all obj files and uic files and recompile, q_object vtable error. It still fails.


    Go to trolltech's mail lists to find the reason: Because when qmake generates the Makefile, there is no Q_OBJECT in the header file of this class, so the moc xxx.h command is not used in the corresponding Makefile, which eventually causes the link to fail. Re-run qmake, the problem solve.


    When looking for a solution, I found one point:


    qmake will not process the Q_OBJECT in the .cpp file, so if it is in the .cpp file, it q_object vtable error also generate an undefined reference to vtable for "xxx::xxx". At this time, scp no match error need to use moc xxxx.cpp to generate the corresponding The moc file of the .cpp file can be included to solve this problem. Know your problem, the above example is not good, because hp500 system error 02 10 put the main and the class together. If they are separated, there may be no problem, including the separation of h and cpp.

    To solve the above problem, add a line
    #include "main.moc" at the end of your main.cpp

    Then delete all other files except main.cpp. Come over again, no problem.

    Therefore, I guess the problem you mentioned earlier is also not linked to the moc file. You add a line at the end of your myplot.cpp file: #include "myplot.moc" Try it out.


    In addition: if your main does not return a value, the compiler will warn, and the last q_object vtable error of the program does not only contain carriage return, but also warns.

    0 Comments

    Leave a Comment