Error while integration Qt files with existing Visual studio project

  • Hi All,
    I have integrated Some qt class files to my existing Visual studio C++ app. The application is compiling fine without Q_OBJECT and if i am trying to use Q_OBJECT in my project then getting the below error

    error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall Window::metaObject(void)const

    I can understand moc.exe is not getting invoked to generate moc_xx.cpp code.. but how to add moc.exe with visual studio i don't have any idea. Please somebody help me to resolve this issue.

    Thanks Advance :)


  • Moderators

    Are you using vsaddin?

  • Microsoft visual studio 2008

  • Moderators

    Sorry, the question was apparently a bit short.
    Do you use already the "vsaddin": supplied by Qt?

    I assume that your existing project is a bit larger. However, in my personal experience it has been much easier to generate a new Qt based project and included the required source files.

    In addition, is it really necessary to add new files to an existing project (main application). Sometimes encapsulating in new modules is required and you can set up a Qt based project.

  • Thanks for your reply.

    yes i have installed vsaddin and whenever i compile i get the same error. My existing visual studio project is a big one so don't want to create a new Qt based project. Please help me to integrate a new qt based source file which has Q_OBJECT macro.

  • Moderators

    You could setup a new project with some features you are requiring from Qt. Especially you need to have a header with an object inheriting from QObject.
    In MSVC you need to check the different build features. The header file with QObject is having a custom build step. Those build steps are required for moc'ing. However, who knows what comes as next problem.

    I have done such introduction of the custom build steps myself when it was somehow messed by msvc. However, my recommendation is "Think twice". At the day's end the fresh setup of the project may be ways faster. It would be the way I would choose. My projects have a couple of libs with a couple of hundreds source files each. Pulling in existing source files in msvc is certainly boring, but it is rather short with may be an hour. Trying to search all the requirements of custom build steps may be a couple of days and a lot of hair pulled ;-)

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.