当前位置:网站首页>QT adds a summary of the problems encountered in the QObject class (you want to use signals and slots) and solves them in person. Error: undefined reference to `vtable for xxxxx (your class name)‘

QT adds a summary of the problems encountered in the QObject class (you want to use signals and slots) and solves them in person. Error: undefined reference to `vtable for xxxxx (your class name)‘

2022-06-12 11:52:00 There is a long way to go

One : Application scenarios :
1, Create a new parent class , A new subclass has been created , Inherited the parent class , Want to use signal and slot functions in subclasses . Results found connect Function cannot be used .

Two : Implementation steps
1, Add header file #include
2, Your class should inherit public QObject
3, Add a macro to the class Q_OBJECT

3、 ... and : Have a problem
1,error: undefined reference to `vtable for xxxxxx( Your class name )‘.
2,error: undefined reference to xxxxx( This is my parent class )::metaObject() const’.
3, Signal and slot functions implemented in subclasses , The result is to find the slot function in the parent class when using , No slot function found .

Four : terms of settlement
1, Since it is to be used in subclasses , Then take the parent class QObject Class related deletion
2, Write the above implementation steps in the subclass
3, Now that you have added Q_OBJECT This macro , Need to recompile the project
4, Click on qt The construction of —> Clean up all items
5, After cleaning up , Click on the building —> perform qmake( Be sure to execute first qmake, Because we need to Q_OBJECT This macro is compiled into , rewrite Makefile), Most people don't do this , Will be abnormal
6, Click on the run (80% All people will succeed )
7, If the operation is successful , congratulations , I haven't met a very wonderful bug, If the run fails , Let's see if this is my case , It's amazing !
8, Because my subclass is the inherited parent class , So I'm adding QObject Class time , Naturally put this QObject Written later : As shown in the figure below
 Insert picture description here
9, There will be problems with this implementation , Will be submitted to the error
10, hold QObject class , Write to the front , Then you can recompile it , Isn't that amazing
11, Click on the run (99.9% All people will succeed )
12, If you don't succeed , Then you are executing that implementation step , Or delete this class first , Then add again , Or put that build–debug/release Compile Directory , Delete , After recompiling , If not , I don't know , ha-ha .
5、 ... and : The successful running
I wish you all a successful operation , Hey .

原网站

版权声明
本文为[There is a long way to go]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/163/202206121148545059.html