Error LNK2001



  • Hello,

    I'm developing a Windows Mobile 6.5 application with MSVisual Studio 2008 Professional and Qt Visual Studio add-in installed.

    I have a class with slots and signals, so I put Q_OBJECT in its header. If I build the project it compiles but doesn't link fine. I'm getting this errors:

    @(...)error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __cdecl(...)
    (...)error LNK2001: unresolved external symbol "public: virtual void * __cdecl(...)
    (...)error LNK2001: unresolved external symbol "public: virtual int __cdecl(...)@

    I've readen in a guide of Qt this:

    bq. If this ever happens to you, run qmake again to update the makefile, then
    rebuild the application.

    But I don't know what I must do if I work with MSVisual Studio 2008 Professional and Qt Visual Studio add-in installed.

    Thank you very much,
    SBC



  • You should reimport your .pri file. You have split your qmake project into .pro for the general settings, and .pri containing the file lists (HEADERS, SOURCES, FORMS), do you?

    Otherwise you must add the moc steps for the newly QObjectifyed class manually.



  • I have faced the same issue but regenerating Makefile and rebuilding project solved the issue



  • I didn't add new files (classes and headers) to .pro file....I did it and run qmake another time and it has worked.

    But one thing, I didn't have a .pri file, why is it necessary?

    Thank you very much!!



  • It's not really necessary, but works well with the Visual Studio AddIn.

    If you import a .pro file, the VS project will be regenerated from scratch and you are loosing all modifications you did manually (optimizations, special path settings and so on). Most times you will have added new classes and forms to your project and want to pull them into the VS project. This is where the "import .pri into current project" of the AddIn comes in. It leaves your settings as is and just add/remove the sources and adds the moc and uic steps if necessary.

    The import step is also necessary, if you add the Q_OBJECT macro to a class later on.

    If you are on the command line and use nmake to compile your project, all this "magic" is not necessary then; just re-run qmake.



  • Ok Volker, thank you VERY MUCH!!


Log in to reply
 

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