Qt - Visual studio 2010 , Moc changing CPP file causes link error. forces me to rebuild moc files
-
I am using QT VS 2010 for some reason if I make a change to a cpp file that is tied to a ui. I am forced to rebuild the moc files. If I don't I will get linker errors. I can live with the rebuild. The problem is The only way I am able to get the moc files to build is to re-create my vcproj.
Is there a way I can force moc files to be re-built every compile?
When I compile I do see the following message for each .h file Moc'ing xxx.h...
-
Do you have "vs-addin":http://qt.nokia.com/downloads/visual-studio-add-in installed ?
You need to have a licensed version of msvc for using vs-addin. -
You have only custom build steps for your .ui and your .h.
For example you have- BrowserWindow.ui
- BrowserWindow.h
- BrowserWindow.cpp
If you change BrowserWindow.cpp only this file requires compilation. If you change BrowserWindow.h this file will be moc'ed and BrowserWindow.cpp will be compiled. If you change the .ui file the ui file will be uic'ed and rest will follow too. That should be enough to my understanding.
However, if you want to force a moc'ing of .h you can go to the properties for that file. You might be able to add the additional dependency to .cpp.
I am using msvc 2005, so I do not know how this looks in vc 2010, but I assume that there is a possibility to do so.
Once again, I have checked in a project of mine. The dependencies are set that with a changed .cpp only this file is compiled.
-
OK. You need to check then the "Outputs" property for your header files then. It typically sais something like "./generatedfiles/" with some macros attached.
Other solution could be to remove the files in question from your project. Beware, to make a backup first. But that is probably what you mean with regenerate .vproj, isn't it?
I had to do this recently, but it works ever since. -
I do not use .pro files for msvc. Respectively, only for getting the project struture to qt creator on linux.
Can you trace the output? Are the files created where they are supposed to be created?
In msvc 2005 I removed (not delete!) the files and added them as existing files again. That cured recently my problem.
-
-
The exclude from build is handled by vs addins I assume or it must be handled by msvc itself.
In msvc 2005 it looks like this:
!http://db.tt/1OzWlfNv(GeneratedFilesSection)!
This is for compilation in debug mode. The release mode shows the "excluded from build" stop sign at right. The debug section does not because that is debug mode. When switching to release mode it will be the other way around.
As explained above I had an issue there as well recently. I was removing from the project (do not delete the files) the adequate header, source and ui files and adding them to the project again with "add existing files". This procedure cured the problem.
Before that I was fiddling around with the properties but that confused only the whole build process even more. -
I got stuck in this same problem earlier today. I tried build clean on my project and started getting the "c1xx : fatal error C1083: Cannot open source file: 'Release\moc_xxxx.cpp': No such file or directory" errors.
After much frustration with vs2010, I figured two things out:
I could get the moc_xxxx.cpp files to come back using the "Restore previous versions" options that came with my version of Windows. Every time you update windows, it takes a snapshot of your recently changed files and saves it on your harddrive.
After getting it to that point, I also found another "fix" but this is more of a hack than a fix. For every .h file that you want to force Moc'ing for, (so any of them with a Q_OBJECT macro in them) you can tell visual studio to explicitly build the .h file (right click on the file and choose compile, or press Ctrl-F7 while in the .h file).
Then the next time you build, it can find the Moc'ed file and the error goes away.
I hope that helps someone.
It would be nice if there was an option built into the Qt menu on the VS plug-in that could do that for you (such as "Regenerate All Moc Files") or if it could notice that the moc files don't exist and built them so that you can recover after a build clean.