Qt Qobject Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or undefined reference to vtable qobject posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss
Undefined Reference To Vtable Qt Cmake
Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only
Undefined Reference To Vtable For Class Qobject
takes a minute: Sign up Q_OBJECT throwing 'undefined reference to vtable' error [duplicate] up vote 40 down vote favorite 15 This question already has an answer here: Qt Linker Error: “undefined reference to vtable” 8 answers I'm using Qt Creator
Undefined Reference To Metaobject Const
2.0.1 with Qt 4.7.0 (32 bit) on Windows 7 Ultimate 32 bit. Consider the following code, which is a minimum to produce the error: class T : public QObject, public QGraphicsItem { Q_OBJECT public: T() {} QRectF boundingRect() const {return QRectF();} void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {} }; int main() { T t; return 0; } The above code fragment causes the following linker errors: In function `T': undefined reference to `vtable for T' undefined reference to `vtable qt undefined reference to vtable for constructor for T' In function `~T': undefined reference to `vtable for T' undefined reference to `vtable for T' If I comment out the line that contains Q_OBJECT, it compiles fine. I need signal and slots with QGraphicsItem so I need Q_OBJECT. What is wrong with the code? Thanks. c++ qt linker-error vtable share|improve this question asked Jan 23 '11 at 14:24 Donotalo 7,167145993 marked as duplicate by djf, Rubens, Phil Hannent, tjameson, John Doyle Jul 13 '13 at 19:03 This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question. add a comment| 5 Answers 5 active oldest votes up vote 71 down vote accepted 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. share|im
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and error: undefined reference to `vtable for ' policies of this site About Us Learn more about Stack Overflow the qt moc files company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags the vtable symbol may be undefined because the class is missing its key function Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only http://stackoverflow.com/questions/4774291/q-object-throwing-undefined-reference-to-vtable-error takes a minute: Sign up Error with QObject::connect() up vote 1 down vote favorite I am trying to run QTimer and have it warn me when timeouting. To do so, I use slot and signal to link the two. The guy.h: #ifndef GUY_H #define GUY_H #include
download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript). Home Qt Development General and Desktop How to inherit from QObject https://forum.qt.io/topic/27051/how-to-inherit-from-qobject-directly directly? How to inherit from QObject directly? This topic has been deleted. https://bugreports.qt.io/browse/QTBUG-25512 Only users with topic management privileges can see it. lanmanck last edited by Hi,Guys: I define a new class and found it cannot inherit from QObject, the complier will report an error:undefined reference to vtable for XX an example from here:http://harmattan-dev.nokia.com/docs/library/html/qt4/unix-signals.html cannot be compiled correctly. Reply Quote 0 mcosta undefined reference last edited by Hi, you can inherit directly from QObject. If you class implements signals or slots you must provide Q_OBJECT macro in provate part of you class definition. For Example @ class MyObject: public QObject { Q_OBJECT public: MyObject (QObject *_parent); ..... }; @ Once your problem is solved don't forget to: Mark the thread as SOLVED using the Topic Tool undefined reference to menu Vote up the answer(s) that helped you to solve the issue You can embed images using (http://imgur.com/) or (http://postimage.org/) Reply Quote 0 mranger90 last edited by Also note that the class definition has to be in a separate include file or the moc will not generate the code. A common cause of this error is to have the class definition and the code in main.cpp. Reply Quote 0 utcenter last edited by ^^^ That is not necessary - you can do the implementation entirely in the header file, the reason you also need the cpp file is because the moc generated code will be inserted there. You can pretty much leave an empty cpp file, but without it you will get compilation error. Reply Quote 1 lanmanck last edited by thanks guys. I read this thread:http://qt-project.org/forums/viewthread/1227/ and in main.c I MUST construct the class, or it will report an compile error. Reply Quote 0 mranger90 last edited by utCenter - you are correct. But I was addressing this situation: @ #include "mainwindow.h" #include
base to derived typeAgile Board ExportXMLWordPrintable Details Type: Bug Status: Closed Priority: Not Evaluated Resolution: Invalid Affects Version/s: 4.8.1 Fix Version/s: None Component/s: Build tools: moc, Core: Object Model Labels: None Environment: Ubuntu 12.04 Description During compiling there every time a error occurs while compiling moc file. It happpens because *_t = static_cast< ... > is used. I think there should be written dynamic_cast. I also attached the moc file. error message: moc_my_header.cpp: In static member function 'static void MyNamespace::MyInterface::qt_static_metacall(QObject*, QMetaObject::Call, int, void**)': moc_my_header.cpp:48: error: cannot convert from base 'QObject' to derived type 'MyNamespace::MyInterface' via virtual base 'QObject' Here my example code: #ifndef MY_HEADER_H #define MY_HEADER_H #include