Qt4 in Visual Studio 2008 - are moc-ed files excluded from assembly?

I recently installed VS Addin from Qt Software, and I imported my .pro project into VS2008. As a rule, everything works fine, with one small but annoying exception.

Suppose I have a .cpp file with a class that declares that it is Q_OBJECT. Thus, the MOC-ed file and moc_file.cpp are generated and available in the solution in the "Generated Files" section. So far so good.

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

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

+6
qt visual-studio-2008
source share
6 answers

The problem is resolved. I found out that in my manually processed .pro file describing my project, I had MOC_DIR specified as:

MOC_DIR = .moc

After importing into Visual Studio, the directory for "Generated Files" was the same for Release and Debug. So, when my active configuration was Debug, for example, when I saved the file, it was excluded from the assembly because it was reasonable for the Release-related file, just like the RPG, and Andrew suggested. After changing the directory to .moc \ $ (ConfigurationName), the problem is no longer visible (and I see two versions of each generated file in my solution - one for each configuration).

Thanks for all your help!

+7
source share

Actually, I found a solution for this "function". You must add BOTH files from GeneratedFiles \ Debug and GeneratedFiles \ Debug (or from other configuration directories). Qt excludes everything from the assembly that does not apply to the currently selected assembly type.

+1
source share

Yes, I am using the latest version of VS Addin, and my project is correctly viewed as a Qt project.

0
source share

Have you configured your configuration correctly?

Open the "Debug Settings" window. Set the following items as follows:

  • Command line build qmake-project and qmake and nmake debug
  • Clean Commands nmake debug-clean
  • Rebuild command line qmake and nmake debug

Repeat the same with the release configuration.

0
source share

I saw an exception to the build behavior in VS2008 (VS 2003 too), but the project is building correctly. When you change the moc'able file, Qt will have to recreate the moc'ed file because it is deprecated.

I suspect the Qt algorithm looks something like this:

  • determine that the file has been modified
  • set the old moc file as excluded from the assembly
  • add a new file to the project with the same name and include it in the assembly

In my VS 2003 project, I see that some moc_ * files are included in the project twice, one version is installed as excluded from the assembly, and the other is not.

0
source share

Recreating the .vsproj file with qmake may fix the problem.

For each QObject file that you have, the QT plugin creates a moc_ file for each build configuration (usually just Debug and Release). When you change the current configuration, you can see that the input characters do not go from one file to another.
The moc_ files should not change when the .cpp file is modified. only when you change .h files. All this leads me to the fact that something wrong happened to your configuration, and the really best way to fix this is to recreate it with qmake, using something like this:

 qmake -spec win32-msvc2008 
0
source share

All Articles