Problem with moc_* file

  • I use QT with vs2008, I suffered the following problem for quite a lot of times, never found the reason and the method to slove it.

    Sometimes I write a new class with Q_OBJECT declared in it, the project runs well, then I do some changes to the class(very small changes), the moc_* file which the compiler generated is empty! so link error appears like this:

    error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall MainWindow::metaObject(void)const " (?metaObject@MainWindow@@UBEPBUQMetaObject@@XZ)

    So I remove all the changes, but the situation doesn't change, the moc_* file remains to be empty!

    I really want to know why?! Thank you very much for any possible answer and attention!

  • I haven't seen this behavior. What I do see often is

    • Adding a header file with Q_OBJECT in the class definition doesn't get visual studio to do the moc step

    • Adding or removing Q_OBJECT from the header file doesn't trigger the moc step

    Remove and add the header file again works around both of these. Maybe you should try your luck on it :). If that fails and it's a non-proprietary project you could post it here (or somewhere at least) so people can have a look at the project settings. (zipped of course)

  • I never have a problem with VS2008 when using the Qt addon. The addon is great, does the pre-build step for you and also adds the moc file to the project. It's worth checking out.

Log in to reply

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