Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt moc.exe not generating *.moc file

Tags:

qt

qmake

nmake

I'm trying to build the qtestlib/tutorial1 example, but the testqstring.moc file isn't being generated when I run nmake (I'm running Qt 4.5.2 on Windows XP SP3).
I copied testqstring.cpp from the tutorial directory to my build directory (C:\sandboxes\testqstring) and from the Qt command prompt ran vsvars32.bat file from my MS Visual Studio 8 installation to add the VS environment variables.

According to the tutorial, I should run:

> qmake -project "CONFIG += qtestlib"
> qmake
> nmake

When I do, the output from nmake is:

C:/Apps/Qt/2009.03/qt/bin\moc.exe -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_TESTLIB_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -I"....\Apps\Qt\2009.03\qt\include\QtCore" -I"....\Apps\Qt\2009.03\qt\include\QtGui" -I"....\Apps\Qt\2009.03\qt\include\QtTest" -I"....\Apps\Qt\2009.03\qt\include" -I"." -I"....\Apps\Qt\2009.03\qt\include\ActiveQt" -I"debug" -I"....\Apps\Qt\2009.03\qt\mkspecs\win32-g++" -D__GNUC__ -DWIN32 testqstring.cpp -o debug\testqstring.moc

g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_TESTLIB_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -I"....\Apps\Qt\2009.03\qt\include\QtCore" -I"....\Apps\Qt\2009.03\qt\include\QtGui" -I"....\Apps\Qt\2009.03\qt\include\QtTest" -I"....\Apps\Qt\2009.03\qt\include" -I"." -I"....\Apps\Qt\2009.03\qt\include\ActiveQt" -I"debug" -I"....\Apps\Qt\2009.03\qt\mkspecs\win32-g++" -o debug\testqstring.o testqstring.cpp

testqstring.cpp:63:27: testqstring.moc: No such file or directory
NMAKE : fatal error U1077: 'C:\Apps\Qt\2009.03\mingw\bin\g++.EXE' : return code '0x1' Stop.
NMAKE : fatal error U1077: 'C:\PROGRA~1\MICROS~3\VC\BIN\nmake.exe' : return code '0x2' Stop.

So, I can see that moc.exe is being called to generate debug/testqstring.moc, but that file is never generated.

Thank you for any and all guidance you can provide.

like image 1000
Doug Cuthbertson Avatar asked Aug 29 '09 12:08

Doug Cuthbertson


3 Answers

It looks like you're trying to use nmake to do a build with MinGW. nmake is an MSVC tool.

If you want to do a build with MinGW you must use mingw32-make. If you want to do a build with MSVC you must use a Qt built with MSVC (which means you have to build it yourself or have a commercial license).

like image 185
rohanpm Avatar answered Nov 16 '22 22:11

rohanpm


I had the problem that the moc.exe didn't generate any moc-files with nmake. The reason was a wrong moc.exe path inside the Makefile.Debug.

Something like:

C:/Qt/2009.03/qt/bin\moc.exe

I change it to:

C:\Qt\2009.03\qt\bin\moc.exe

and now it works. ;)

Unfortunally qmake will generate the makefiles everytime you run it from the menu or rebuild/clean the solution/project. I think it's a bug of the qmake configuration.

To fix it permanently you have to find the file C:\MyQtDir\mkspecs\win32-msvc2008\qmake.conf. For other configs you have to change win32-msvc2008.

For me it was at C:\Qt\2009.03\qt\mkspecs\win32-msvc2008\qmake.conf

Search for the phrase "QMAKE_MOC". You will find some lines like this:

QMAKE_MOC               = $$[QT_INSTALL_BINS]\moc.exe
QMAKE_UIC               = $$[QT_INSTALL_BINS]\uic.exe
QMAKE_IDC               = $$[QT_INSTALL_BINS]\idc.exe

QT_INSTALL_BINS is a path that seems to be wrong. The directory separators are still '/' but should be '\'. At the moment I don't know exactly where I have to change QT_INSTALL_BINS. But the qt path won't change for me so I replaced the macro by hard-defined pathnames:

QMAKE_MOC               = C:\Qt\2009.03\qt\bin\moc.exe
QMAKE_UIC               = C:\Qt\2009.03\qt\bin\uic.exe
QMAKE_IDC               = C:\Qt\2009.03\qt\bin\idc.exe

Now there are no problems with the moc anymore. Rebuilds will work fine too.

Hope this helps ;)

like image 42
Bersi Avatar answered Nov 16 '22 21:11

Bersi


Have you tried using the compiler/tools included with Qt in /mingw/bin? (On my system, Qt is installed in C:\Qt\2009.03.) Last time I checked, the non-commercial distribution of Qt will not work with Visual Studio. I just tried this from the Qt command prompt and it worked.

qmake -project "CONFIG += qtestlib"

qmake

mingw32-make

Hope this helps.

like image 1
kenrogers Avatar answered Nov 16 '22 23:11

kenrogers