Qt's reason for "undefinedreferenceto 'vtablefor" -- Linux general technology-Linux programming and kernel information. The following is a detailed description. Due to the limited implementation mechanism of Qt itself, when we use Qt to create some software programs, we will encounter various such problems, and many of them are very difficult, or you cannot find the cause. Even if you solve the problem, if someone asks you why, you can only answer the question;
Today, the questions I listed here are the problems that I always encounter when I compile the Qt program. The questions are common, but the answers are not unique. There are many explanations for this question, this error is often only applicable to one situation, because it is too general. It is -- "undefined reference to 'vtable for" which may be quite familiar to you, it seems that you have encountered this problem in the c ++ program. You are right. Sometimes this error is not only caused by qt, but also caused by your c ++ program;
I have collected some online symptoms, corresponding solutions, and causes. I have basically verified them and included them for backup;
I. The pre-compiler opens the macro Q_OBJECT and declares several member functions processed by moc (implement. If a compilation error similar to "undefined reference to vtable for LcdNumber" is returned (if you get compiler errors along the lines of "undefined reference to vtable for LcdNumber "), you may have forgotten to execute moc or add the moc output to the link command.
If Q_OBJECT is added to a class, the link prompt is: undefined reference to vtable for "xxx: xxx". No problem occurs if you delete it.
Solution: Try (1): delete all obj files and uic files and recompile the files.
Go to the mail lists of trolltech to find the reason: because qmake does not include Q_OBJECT in the header file of this class when generating Makefile, moc xxx is not used in the corresponding Makefile. h command. run qmake again to solve the problem.
When looking for a solution, you will find one point:
Qmake will not process. the Q_OBJECT in the cpp file. in the cpp file, undefined reference to vtable for "xxx: xxx" will also be generated ". in this case, use moc xxxx first. cpp generates the corresponding moc file and then includes it. cpp to solve this problem.
Here we can find that the problem occurs because no moc generates the corresponding moc file, and then the connection fails.
I found a lot of problems such as the source code, that is, I didn't find the pro error. Later I thought that we had make in the moc of qt.
Qt make compilation is based on Makefile, while Makefile is based on the pro file. This reminds me of the error of finding the pro file.
Ii. undefined reference to vtable for "xxx: xxx"
I encountered this problem today.
Cause: qmake will not handle the issue. the Q_OBJECT in the cpp file. in the cpp file, undefined reference to vtable for "xxx: xxx" will also be generated ". in this case, use moc xxxx first. cpp generates the corresponding moc file and then includes it. cpp to solve this problem.
Others:
1. problem: The function in QGLViewer cannot be properly linked. solution: Check the source code and find that Qt 3 is used for compiling when libQGLViewer is installed from the source code, while Qt4 is used for compiling in my program. therefore, you must re-compile it with Qt4. however, after changing the QTDIR environment variable to Qt4 and re-compiling, qmake generates a makefile error. it is further found that although QTDIR is set to Qt4, Qt4 is used for header files and library files, moc, uic, and so on are all in qt3 version. After changing the PATH environment variable, everything is OK.
2. problem: If Q_OBJECT is added to a class, the link prompt is: 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 them. still failed. go to the mail lists of trolltech to find the reason: because qmake does not include Q_OBJECT in the header file of this class when generating Makefile, moc xxx is not used in the corresponding Makefile. h command. run qmake again to solve the problem. when searching for a solution, qmake does not handle the problem. the Q_OBJECT in the cpp file. in the cpp file, undefined reference to vtable for "xxx: xxx" will also be generated ". in this case, use moc xxxx first. cpp generates the corresponding moc file and then includes it. cpp to solve this problem.
3. looking at Qt's reference, we found that connect (pObjA, SIGNAL (someSignalA (), pObjB, SIGNAL (someSignalB () can be used; in this way, someSingalA sent by pObjA will cause pObjB to send somesig, thus forming a signal relay.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service