Pregunta

Recibo el siguiente error del vinculador cuando construyo mi aplicación.

HIMyClass.obj::error:símbolo externo no resuelto "público:Struct Virtual QMetaObject const * __THISCALL CHIMYCLASS :: MetaObject (void) const "(? MetaObject@chimyclass @@ ubepbuqmetaObject @@ xz) no se encuentra:HIMyClass.obj

HIMyClass.obj::error:símbolo externo no resuelto "público:Virtual void * __THIscall ChimyClass :: Qt_Metacast (char const *) "(? qt_metacast@chimyclass @@ uaepaxpbd@z) no se encuentra:HIMyClass.obj

HIMyClass.obj::error:símbolo externo no resuelto "público:virtual int __thiscall chimyclass :: qt_metacall (enum QmetaObject :: call, int, void * * *) "(? Qt_metacall@chimyclass @@ omaehw4call@qmetaobject @@ hpapax@z) no se encuentra:HIMyClass.obj

Mi declaración de clase es como

class CHIMyClass:public QDialog
{
   Q_OBJECT

   ....

};

Cuando comento Q_OBJECT, el error del vinculador aparece (y obviamente no puedo usar señales ni slots).Estoy usando Qt Creator como IDE y Qt 4.5.3.cuando doy Reconstruir todo es definitivo que Qhacer sera llamado.Supongo que es en la generación de archivos moc_* donde radica el problema.Estoy usando Windows XP y cl como compilador.

¿Cuál podría ser la razón detrás de este error del vinculador?

¿Fue útil?

Solución

Dichos errores generalmente significan que no ha agregado el encabezado de su clase a la variable "encabezados" en el archivo PRO (el compilador META OBJETE genera archivos MOC_ solo para los encabezados enumerados en esta variable).¡Recuerde ejecutar QMake después de cambiar el archivo .pro!

Otros consejos

Tuve un problema similar y se resolvió con los comentarios de Andref.Dentro de Qt Creator I Simplemente:

  1. construir / limpiar todo
  2. construir / ejecutar qmake
  3. construir / ejecutar

Siempre que cambie la herencia de QObject, asegúrese de hacer un clean, qmake entonces build.El qmake es importante ya que actualiza los archivos moc* para cualquier cambio nuevo de Qt en sus archivos .h, incluida la herencia de QObject, es decir Q_OBJECT.De hecho, en algunos casos, es posible que incluso puedas simplemente hacer qmake entonces build para una construcción incremental.

Check in the file MakeFile.debug and maybe HIMyClass don't exists.

I just rename MakeFile.debug, Clean the Project and Rebuild All and it compiles.

I had the same problem but in my case it wasn't enough to clean -> build. So I had to delete manually all files created in build process (Mekefiles, ui descriptionns in cpp, and generally whole directory created by build process) and only then build succeded.

Check that the necessary Qt config options are present in the pro file (QT += core gui at least. Also try manually deleting everything built/created in the build directory. It sometimes happens that moc fails to run for some reason.

You can also try running the moc command yourself, and see what it outputs (you can find the command line in the tab "Compile output" in QtCreator.

UPDATE: this related problem seems to suggest you don't define QT_DLL when compiling. Can you try a fresh and new simple QtCreator project (with a widget that subclasses mainwindow for example) and try that. It should contain a Q_OBJECT header automatically and try to compare the .pro files and compiler output.

on my osx box this was due to missing moc* files. i fixed this by removing the bom from my utf-8 encoded .pro file. i will file a bug with qt.

error for goggle searches... NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.

"vtable for MainWindow", referenced from:

 MainWindow::MainWindow(QWidget*)in mainwindow.o

I found another possible cause and solution to this error

This error will also occur if one has declared the slot in .h file but has not defined its body in the implementation

I had this problem. Verify whether there is a description of the implementation of the slot in .cpp file.

I had removed #include "main.moc" from my main file, and forgot to re-add it... That was a fun time-waster!

Answers from @chalup and @ierax helped me. I had to close the Qt creator and open it again though for qmake to take effect. I followed these steps: 1. Moved the class definition to a header file. 2. Added header file to project and ensured it is listed against HEADERS += \ list in .pro file. 3. Clean-all 4. close QtCreator (on Windows 10) 5. Delete Makefiles from the project directory 6. Open QtCreator and open the project. 7. Qmake to ensure makefiles are generated. 8. Rebuild-all

These steps helped me solve this issue - I struggled for over an hour with various other answers and methods nothing worked. Before you run qmake ensure you delete makefiles and close QtCreator (applicable atleast on windows 10).

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top