tags:

views:

2709

answers:

6

Hi, 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.

A: 

Ar you sure the moc isn't generated? It lives in the Debug directory, so you will either need to #include "Debug/teststring.moc" or #include with an additional -IDebug compiler option.

drhirsch
If you look at the compile line you can see it already includes -I"debug". The user doesn't need to explicitly do this in the .pro file.
Intransigent Parsnip
A: 

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.

kenrogers
Thanks, mingw32-make did the trick. I thought it would just work with nmake. The tutorial only mentioned make and nmake. Since I have MSVC, I thought nmake was the right tool. Obviously, it wasn't.
Doug Cuthbertson
+2  A: 

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).

Intransigent Parsnip
Thanks. I knew it would be something simple. mingw32-make works fine.
Doug Cuthbertson
A: 

I had the same problem. But I solved it by removing file qt.conf from /bin directory.

forgot10
+1  A: 

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 ;)

Bersi
You can update the QT_INSTALL_BINS path by running qmake.qmake -set "QT_INSTALL_BINS" "C:\Qt\2009.03\qt\bin"More info here: http://doc.trolltech.com/4.5/qmake-environment-reference.html
Noah Callaway
A: 

In case of yet compiling with VC nmake there is a workaround for this bug here: http://bugreports.qt.nokia.com/browse/QTBUG-6470

vladimir