Error Undefined Reference To Vtable For Qobject
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
Undefined Reference To Vtable Qt Cmake
this site About Us Learn more about Stack Overflow the company Business qt undefined reference to vtable for constructor Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask undefined reference to metaobject const Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign
Qt Undefined Reference To Vtable For Class
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 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 :
The Vtable Symbol May Be Undefined Because The Class Is Missing Its Key Function
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 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,147145993 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 pr
here for a quick overview of the site Help Center qt moc files Detailed answers to any questions you might have Meta
Q_object
Discuss the workings and policies of this site About Us Learn more about Stack qmake Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question http://stackoverflow.com/questions/4774291/q-object-throwing-undefined-reference-to-vtable-error x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Qt undefined reference to vtable [duplicate] up vote 13 down vote favorite 2 This question already has http://stackoverflow.com/questions/14010922/qt-undefined-reference-to-vtable an answer here: Qt Linker Error: “undefined reference to vtable” 8 answers I am a beginner to Qt programming and use codeblocks for my programming. I created 3 files communicate.h,commmunicate.cpp and main.cpp as follows: communicate.h #ifndef COMMUNICATE_H #define COMMUNICATE_H #include
vtable errors If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select http://www.qtcentre.org/threads/37731-QOBJECT-and-undefined-reference-to-vtable-errors the forum that you want to visit from the selection below. Welcome to Qt Centre. Qt Centre is a community site devoted to programming in C++ using the Qt framework. Over 90 percent of questions asked here gets answered. https://www.ics.com/designpatterns/book/moc.html If you are looking for information about Qt related issue — register and post your question. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other undefined reference features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. + Reply to Thread Results 1 to 8 of 8 Thread: QOBJECT and undefined reference to vtable errors Thread undefined reference to Tools Show Printable Version Subscribe to this Thread… Search Thread Advanced Search Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode 11th January 2011,16:53 #1 stargazer View Profile View Forum Posts View Blog Entries View Articles Beginner Join Date Jan 2011 Posts 3 Qt products Platforms QOBJECT and undefined reference to vtable errors I've been working on a plugin to an third party application an have recently introduced a GUI dialogue module into the project. The problem is that I can't get around an error I am getting which is: undefined reference to 'vtable for StelModule' I have reduced my code down to the basics and have discovered that when I remove Q_OBJECT from the class definition within the hpp file the everything compiles Ok. Obviously because this is a GUI it will require Q_OBJECT. I've found a few posts on the subject via Google and it would appear that this is something to do with .moc files. Unfortunately things start to get rather confusing after that, but as far as I understand, QT 4.7.1 (2010.05) should manage this pretty much authormatically. I have seen references to including a .moc file in the .cpp file but there seem to be no .moc files being generated. Insetad I do see a moc_mymodule.cpp and moc_mymodule.o in the debug directory. I'm also confused about what, if anything, should be added to
] QObject supports features not normally available in C++ objects. Signals and Slots (Section 8.5) MetaObjects, MetaProperties, MetaMethods (Chapter 12) qobject_cast (Section 12.2) Some of these features are only possible through the use of generated code. The Meta Object Compiler, moc, generates additional functions for each QObject-derived class that uses the Q_OBJECT macro. Generated code can be found in files with names moc_filename.cpp. This means that some errors from the compiler/linker may be confuscated[67] when moc cannot find or process a class in the project. To help ensure that moc processes each QObject-derived class in the project, following are some guidelines for writing C++ code and qmake project files. Each class definition should go in its own .h file. Its implementation should go in a corresponding .cpp file. The header file should be "wrapped" (e.g., with #ifndef) to avoid multiple inclusion. Each .cpp file should be listed in the SOURCES variable of the project file; otherwise it will not be compiled. Each header file should be listed in the HEADERS variable of the .pro file. Without this, moc will not preprocess the file. The Q_OBJECT macro must appear inside the class definition of each QObject derived header file so that moc knows to generate code for it. Multiple Inheritance and QObject Because each Q_OBJECT macro generates code, it needs to be preprocessed by moc. moc works under the assumption that you are only deriving from QObject once and, further, that QObject is the first base class in the list of base classes. If you accidentally inherit from QObject more than once, or if it is not the first base class in the inheritance list, you may produce strange errors in the moc-generated code. Undefined reference to vtable If you define a QObject-derived class, build an application, realize that you need to add the Q_OBJECT macro to the class definition, and add it after the project was built with an old Makefile, you must then rerun qmake to update the Makefile. make is not smart enough to add the moc step on such files to your Makefile otherwise. A "clean rebuild" does not fix this problem usually. This is an issue that often causes