Due to the limited implementation mechanism of QT itself, we encounter various such problems when using QT to create some software programs, and many of them are very difficult, or it is hard to find the cause. Even if the problem is solved, if someone asks you why, you can only answer: I don't know;
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 very 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 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 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". If this parameter is deleted, no problem occurs.
Solution: Try (1): delete any OBJ and UIC documents 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 document 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 document. otherwise, the undefined reference to vtable for "XXX: XXX" will be generated ". in this case, use moc xxxx first. CPP generates the corresponding MOC document and then includes. CPP to solve this problem.
The problem can be found here because MOC does not generate the corresponding MOC document, 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 document. This reminds me of the error of finding the pro document.
From: http://www.cublog.cn/u/16292/showart_136087.html
II:
Undefined reference to vtable for "XXX: XXX"
Today I encountered this problem and finally Google it:
Http://www.cublog.cn/opera/showart.php? Blogid = 8650 & id = 49526
Original cause: qmake will not process. the q_object in the CPP document. otherwise, the undefined reference to vtable for "XXX: XXX" will be generated ". in this case, use moc xxxx first. CPP generates the corresponding MOC document and then includes. 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, both the header document and Library Document make
Qt4 is used, but MOC and UIC are all in qt3. After changing the PATH environment variable, everything will be 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 any OBJ and UIC documents and recompile them. still failed. go to trolltech's mail lists to find the reason:
When qmake generates makefile, there is no q_object in the Class header file, so 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 document. otherwise, the undefined reference to vtable for "XXX: XXX" will be generated ". in this case, use moc xxxx first. CPP generates the corresponding MOC document and then includes. CPP to solve this problem.
3. looking at QT's reference, we found that the ability to connect (pobja, signal (somesignala (), pobjb, signal (somesignalb (); in this way, somesingala from pobja will cause pobjb to send somesign, thus forming a signal relay.
Link: http://hi.baidu.com/apxmgsfergbdkxq/item/a466a7d58558d34dddf9beda