Qt metaObject linker problem

后端 未结 8 576
猫巷女王i
猫巷女王i 2020-12-30 01:03

After integrating Qt with Vs and trying to compile .pro file I\'m getting following errors:

Error   9   error LNK2001: unresolved external symbol \"public         


        
8条回答
  •  被撕碎了的回忆
    2020-12-30 01:17

    You usally get these errors when the moc_foo.cpp for foo.h (which contains your class marked with Q_OBJECT) is not compiled / linked in your project.

    To make a Qt project work in VS you either

    1. Create a .vcproj file with 'qmake -tp vc' or
    2. Use the Qt Visual Studio Add-in which handles all the moc magic automatically for you (doesn't work with VC Express versions though).

    When using the add-in you can trigger the creation of the moc_foo.cpp by

    • Make sure the header file of the object in question appears in the VS project
    • List item
    • remove all occurrances of Q_OBJECT from the header file of Multiplication_dialog.
    • save the file
    • add Q_OBJECT again
    • save the file

    Now you should have two versions of moc_multiplication_dialog.cpp in your "Generated Files" folder in the Solution Explorer. One for "Debug" and one for "Release". Make sure that one of these files is not excluded from build.

提交回复
热议问题