PDA

View Full Version : Invoking MOC w/MSVS + Qt Visual Integration



WinchellChung
24th July 2007, 16:17
I'm running Microsoft Visual Studio 2005 (2.0.50727) with Qt Visual Studio Integration 1.2.2
I have a legacy application written by a person who is unavailable.
I added a new class by adding a new *.h header file and a new *.cpp C++ file. The new class was based on QObject, and the header file dutifully included the Q_OBJECT macro at the top of the class definition, along with some slots and signals.

When I compiled my project, I got a lot of error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall... errors. Examining the build output, I realized that MOC had been run on the original files, but not on my new file. There was no *_moc.cpp file generated for my new class.

I manually ran MOC.exe on my new header file, and manually inserted the resulting moc file into my project. This compiled and ran perfectly.

So my question is: what am I doing wrong to cause Qt Integration to fail to automatically run MOC on my new class?

jpn
25th July 2007, 05:45
See Tools->Options->Qt->General->AutoUpdateMocSteps.

PS. I'm not sure since which version was this option added, but try checking it out.

WinchellChung
25th July 2007, 14:19
See Tools->Options->Qt->General->AutoUpdateMocSteps.
Thanks, but alas, it was already set to TRUE.

As a work-around, I opened up the properties for the *.h file in question, went to Configuration Properties|Custom Build Step|General, and entered the following:

Command line: $(QTDIR)/bin/moc -o $(InputName)_moc.cpp $(InputPath)
Description: Running MOC on $(InputPath)
Outputs: $(InputName)_moc.cpp

But it would be nice if the Qt Integrator would notice the presence of the Q_OBJECT macro and automatically add this.

andersi
20th November 2007, 19:23
HI!

I saw this question which did not seem to have been closed. I was searching for the same problem after a re-install after win crash. I have Visual .net 2003 and qt4.3.2 and the vs-integration 1.3.2

I added a *.h with a QOBJECT and no moc stage was created.

in previous version of the VS integration there was a moc button but no more. But as I found somewhere out there this is the trick:

Actually so easy, just open the *.h file edit it (add a space for example) and save, then like magic the moc stage is there.

/Anders

verigySupport
10th August 2010, 22:56
The sequence to get auto moc support is finicky but it does work if you add the .h file under Source Files by right-clicking in the solution explorer and choosing Add -> Existing Item. This must be done before the first build after the corresponding .cpp file is added. That was the mistake I made. If moc support is enabled you will see "compile" as a right-click menu item for the .h file. Also looking at the properties you will see a dependencies rule that runs moc.

I am using Qt studio add in version 1.1.5 and VS studio 2008