views:

968

answers:

6

Hi all,

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.

Suppose I have a file.cpp with has a class which declares that it is a Q_OBJECT. So, as such the file is MOC-ed and moc_file.cpp is generated, and is available in Solution under "Generated files". So far so good.

The funny thing is, when I change something in file.cpp (add a line, for example), and save the file using Ctrl+S, the moc_file.cpp becomes excluded from build (you can see a no entry sign on the icon). And I hit lots of typical linker errors when I press F7 to build a solution. In order to fix the situation, I need to go to the properties of moc_file.cpp and change "Exclude from build" from "Yes" to "No". Then everything works fine.

Is someone else experiencing the same? Am I doing something wrong?

A: 

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

prism
A: 

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

A: 

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.

rpg
A: 

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
shoosh
+1  A: 

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.

+2  A: 

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!

prism
I ran into the same issue when importing a .pro in VS 2008 and indeed, some of the "generated" folders were missing the $(ConfigurationName) part. P.S: You should accept your own answer so that this question will not show up in the unanswered section. ;-)
rpg