Comments, Code and Qt. Some words about the wonderful world of software engineering

31Mar/113

Compiling Qt/3D for Windows

I needed to compile Qt/3D for Windows and while doing this I noted a few details I needed to be aware of before I was successful with it. It is worth noting that the build instructions for Qt/3D are available here, but I want to comment on a few details I came across.

Compiling Qt 4.7 for Windows

Qt/3D is not (yet) part of Qt so you need to obtain the source code from here: http://qt.gitorious.org/qt-labs/qt3d. When you do so, please be aware that you also need to compile your own Qt from source! This is because Qt/3D relies on some private headers that are only available when you compile Qt from source for your system. But there are a few things when configuring Qt for Windows that you need to be aware of. Use the MS Visual Studio 2010 compiler Strictly speaking you don't need to compile Qt with MS Visual Studio and you could use MinGW instead, but you do need to compile Qt/3D with MS Visual Studio (a few words about that later). So it is easier just to use one compilation environment to start with. You can obtain a free copy of MS Visual Studio 2010 from here. Just open the MS Visual Studio 2010 Command Prompt from Windows' Start menu and the Windows command line prompt is configured to use the MS Visual Studio compilation environment. In the command prompt go to the location where you downloaded or cloned Qt source code to and you can run configure.exe to configure Qt for compilation. You can find normal Qt build instructions for Windows here. Do not specify the -opengl argument when configuring A few words regarding the configuration process. It might feel tempting to specify the -opengl argument when configuring Qt. After all, we are compiling Qt for Qt/3D and we definitely want to use OpenGL for that. But do not give the -opengl argument at all! There are, in fact, two bugs in Qt configure.exe regarding this.
  1. In some (deprecated) documentation it says that configure.exe can take the -opengl argument alone. If you do this, you will be prompted to accept the license agreement. When you accept the license agreement by pressing the 'y' key, you'll notice that configure.exe will exit on you and nothing more will happen! This is very confusing indeed. But in fact, you will notice that right before the license agreement, there is an error message saying that the -opengl argument is not complete. There's a Qt bug about this issues here: http://bugreports.qt.nokia.com/browse/QTBUG-18459.
  2. If you give the argument -opengl desktop Qt will be built with EGL / OpenGL ES support! This will not work. There's a Qt bug about this issue here: http://bugreports.qt.nokia.com/browse/QTBUG-17997. If you do this, while compiling Qt you will see errors like
egl\qegl.cpp: In static member function 'static void QEglContextTracker::deref()
':
egl\qegl.cpp:67: error: 'eglTerminate' was not declared in this scope
egl\qegl.cpp: In constructor 'QEglContext::QEglContext()':
egl\qegl.cpp:91: error: 'EGL_NO_CONTEXT' was not declared in this scope
egl\qegl.cpp:93: error: 'EGL_NO_SURFACE' was not declared in this scope
egl\qegl.cpp: In member function 'bool QEglContext::isValid() const':
But don't worry - OpenGL should be compiled in Windows by default (you can verify this in the configure output right before it starts to compile qmake). As stated in the Qt installations instructions for Windows, after the configure is done, just type nmake to compile Qt with MS Visual Studio. After the compilation is done, you need to add the qt/bin directory to your system $PATH environment variable.

Building Qt/3D

Qt/3D is under heavy development by the Qt guys in Brisbane. I am sure things will improve while we go towards Qt 4.8, in which Qt/3D should be integrated to, but while we wait for this to happen, here are some things I had to take care of before everything worked for me. Build Qt/3D with MS VS 2010, MinGW will not work Ok - so you have your own Qt compiled from source. Be sure to verify that you use that version of Qt by setting the $PATH environment variable to point to the recently compiled version's bin/ directory, or you can also compile Qt/3D in Qt Creator by adding the newly created Qt there. I first tried to build Qt/3D with the MinGW compilation environment, but that didn't work. If you try to build Qt/3D with MinGW, you will get compilation errors (or at least I got when writing this) about missing declaration for PCRAWINPUTDEVICE as below:
g++" -o debug\main.o c:\src\qt\qt3d\src\plugins\mouse3d\win32input\main.cpp
In file included from
c:\src\qt\qt3d\src\plugins\mouse3d\win32input\/qmouse3dwin32inputdevice.h:49,
from
c:\src\qt\qt3d\src\plugins\mouse3d\win32input\/qmouse3dwin32handler.h:46,
from c:\src\qt\qt3d\src\plugins\mouse3d\win32input\main.cpp:43:
c:\src\qt\qt3d\src\plugins\mouse3d\win32input\/qmouse3dwin32info.h:61:
warning: '__stdcall__' attribute only applies to function types
c:\src\qt\qt3d\src\plugins\mouse3d\win32input\/qmouse3dwin32info.h:61:
error: typedef 'pRegisterRawInputDevices' is initialized (use decltype
instead)
c:\src\qt\qt3d\src\plugins\mouse3d\win32input\/qmouse3dwin32info.h:61:
error: 'PCRAWINPUTDEVICE' was not declared in this scope
c:\src\qt\qt3d\src\plugins\mouse3d\win32input\/qmouse3dwin32info.h:61:
error: expected primary-expression before 'uiNumDevices'
When I compiled using MS Visual Studio 2010 I didn't get this error. So good to be aware of this. Once you have successfully managed to compile the Qt/3D source tree, you are good to go. Just include the qt-3d/bin again to your system $PATH environment variable and do nmake install so that you are able to link against the Qt/3D library and Qt Creator will find the header files. But if you want to use QML/3D you need to be aware of a few more things.

qmlviewer.exe - plugin "qthreedqmlplugin" not found

By default Qt/3D will be compiled in debug mode when you specify 'nmake'. However, it seems that QML expects the Qt/3D plugins to be compiled in release mode or otherwise it will not be able to find them! There is a Qt bug about this issue: http://bugreports.qt.nokia.com/browse/QTBUG-18491 So you will need to compile Qt/3D in release mode if you intend to use QML files together with Qt/3D. You do this simply by giving the compilation command
nmake release
But that's not all.When you compile Qt/3D in release mode, it seems 'nmake install' will not work. So you need to copy the resulting files manually to correct places so that Qt Creator and qmlviewer.exe can use them. Below are the files that you need to copy to the correct places from the qt3d/ source tree to your qt/ source tree.
qt3d/lib/Qt3D.dll => qt/lib/ qt3d/src/imports/threed/release/qthreedqmlplugin.dll => qt/imports/Qt3D/ qt3d/src/imports/shapes/release/ qshapesqmlplugin.dll => qt/imports/Qt3D/Shapes/ qt3d/src/imports/shapes/*.qml => qt/imports/Qt3D/Shapes/ qt3d/src/plugins/sceneformats/assimp/release/qsceneai4.dll => qt/plugins/sceneformats/ qt3d/src/plugins/sceneformats/bezier/release/qscenebezier4.dll => qt/plugins/sceneformats/
Then add qt-3d/bin to your system $PATH environment variable if you already haven't done so. Now it should be possible for you to verify that Qt/3D and QML3D works by running successfully
qmlviewer.exe qt3d/examples/tutorials/teapot-qml/teapot-bounce.qml
Finally everything should work! So it is good to conclude by saying that the qt-quick3d repository is the one Qt will integrate into Qt 4.8 and is under heavy development. The repository contains all the necessary Qt/3D components and integrates the functionality to QML - which you have just achieved. The catch is that if you use this repository, you will not need the private Qt headers and you can use that repository with a binary installation of Qt 4.7.2. Many thanks to sarasmit on #qt-3d@Freenode and Marko Mäkinen for helping me gather this information.

Technorati Tags: , , , , ,

  • emolaus

    Thanks for your help! Perhaps it is worth adding that you need to enter -plaform following the configure command. The list of platforms is under 4.7.x/mkspecs. For MS Visual Studio 2010 it’s e.g.
    configure – -platform win32-msvc2010

    • emolaus

      Gaah the xml tags at the end of the line above were added automatically…

    • Thanks for the tip! I am not sure if I did this, and if you start the MS Visual Studio command prompt should the environment variables so that Qt uses the correct platform when you configure Qt.