Qt4 in Visual Studio 2008 - moc-ed files get excluded from build?

后端 未结 6 1578
野趣味
野趣味 2021-01-01 01:26

Recently I have installed VS Addin from Qt Software and I imported my .pro project to VS2008. Generally, all works fine, with one small but annoying exception.

Suppo

相关标签:
6条回答
  • 2021-01-01 01:29

    Recreating the .vsproj file using qmake might fix the problem.

    For every QObject file you have, the QT plugin creates a moc_ file for every build configuration (usually just Debug and Release). When you change the current configuration you can see the No entry signs go from one file to the other.
    The moc_ files shouldn't change when you change the .cpp file. only when you change the .h files.. All this leads me to thing that something wrong happened with your configuration and really the best way to fix it is to recreate it with qmake using something like this:

    qmake -spec win32-msvc2008
    
    0 讨论(0)
  • 2021-01-01 01:34

    Yes, I use the latest VS Addin and my project is correctly seen as a Qt Project.

    0 讨论(0)
  • 2021-01-01 01:42

    I have seen the excluded from build behavior in VS2008 (VS 2003 too), but the project builds correctly. When you change a moc'able file, Qt will have to recreate the moc'ed file because it is out of date.

    I suspect that Qt's algorithm is something like:

    • detect that file was changed
    • set the old moc file as excluded from build
    • add a new file to the project with the same name and include it in the build

    Looking at my VS 2003 project, I can see that some moc_* files are included twice in the project, one version is set as excluded from build and the other is not.

    0 讨论(0)
  • 2021-01-01 01:43

    Actually, I've found the solution for that "feature". You have to add BOTH files from GeneratedFiles\Debug and GeneratedFiles\Debug (or from other configurations directories). Qt will exclude from build everything what does not belong to the currently selected build type.

    0 讨论(0)
  • 2021-01-01 01:48

    did you set your configuration correctly?

    Open the window "Debug Configuration Settings" Set the following items as stated below:

    • "Build command line" qmake -project & qmake & nmake debug
    • "Clean commands" nmake debug-clean
    • "Rebuild command line" qmake & nmake debug

    Repeat the same with the release configuration

    0 讨论(0)
  • 2021-01-01 01:50

    Problem solved. I found out that in my hand-crafted .pro file describing my project, I had MOC_DIR specified as:

    MOC_DIR = .moc

    After importing to Visual Studio directory for "Generated files" was the same for both Release and Debug. So, when my active configuration was Debug for example, when I saved a file it became excluded from build because it was sensible for Release-related file - just as rpg and Andrew suggested. After changing the directory to .moc\$(ConfigurationName) the problem is no longer seen (and I see 2 versions of each generated file in my solution - one for each configuration).

    Thank you for your help everyone!

    0 讨论(0)
提交回复
热议问题