How can you Earn 30 Dollar Daily ? Click to see the Earning Ways.
Login(Email) Password Forgot Password
Home ASP.net System Info C# Books Java Script Visual C++(MFC) C/C++ Win API Java Contact Us
Browse Category
QT (Open Source or Commercial ) Compilation and Installation Methods
Qt GUI Toolkit is an opensource toolkit using C++ and other languages to code, it is the best GUI library there is. Qt allows you to make Windows, Linux, or Mac programs that work great. We'll explain how to install and trouble shoot some of the errors that come during compilation  on windows .
You can download the lastest version of QT from here (QT for Windows)
Install the programs.
To Compile  QT 4.4.3 you need lastest Mingw . Download for here (Automated MinGW Installer)
 Standard Qt Non-Static Method
1) Now once Qt is installed, you should check your environment variable settings of your computer
   1. Right click -> My Computer
   2. -> Advanced Tab
   3. Environment Variables button
Add the following variables under system variables (correct the paths to suit your needs):

QTDIR -> C:\Qt\4.4.3
MINGW -> C:\MinGW

(Simply edit this one, it exists already) append the following for

PATH -> ;%QTDIR%\bin;%MINGW%\bin;

(Use semi-colons after each statement)
(2) Ok now you should be set, Start->Run->"cmd" and now in the console go to C:\Qt\4.4.3
or wherever your Qt is installed, and first test the variable "QTDIR" by typing "echo %QTDIR%" it should display your path to Qt.

3) Next type in your platform specific configuration option (inside C:\Qt\4.4.3). If you have Windows, use: configure -platform win32-g++ after configure complete . Type mingw-make on the same prompt.

(Note: To use nmake, or Microsoft Visual Studio, then use configure -platform win32-msvc instead) It should start making QMake and getting it ready for you. If you get any errors, your path is not set up correctly, and it cant find the Qt Directory. Trust me if you do it correctly you should have no trouble.

4) Now you can compile projects by using the console to go to your project folder, and typing "qmake -project" (to initialize the .pro file, only need to do this once)
then "qmake" (to update the project file)
then "make" (compile and link; no quotes needed)
If make doesn't work then your MinGW path is not set up correctly and it cant find MinGW\bin. Make sure you can "echo %QTDIR%" or "echo %MINGW%" if nothing is coming up, try restarting command prompt!
Standard Qt Static Method (no DLLs needed)
In this method you will be using qmake and mingw, but this time you won't need to include DLLs of Qt wherever you go, instead they will be added onto your main program, making it bulkier, but at least you won't have to carry around large DLLs.

MingW (Devcpp, code::blocks, notepad++, qmake)
1) Edit mkspecs (c:\Qt\4.4.3\mkspecs\win32-g++\qmake.conf):
Find: QMAKE_LFLAGS = -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc
Replace (to add -static):QMAKE_LFLAGS = -static -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc 2) Now in your Qt command prompt, type:
configure -static -release -no-exceptions
then type:
mingw32-make sub-src This may take a while. Now in your .pro file of your projects, make sure you include this line:
CONFIG += static
so that it will compile your project them statically (or CONFIG += staticlib for .lib compiles).
Microsoft Visual Studio
C++ Static
If you use the opensource version, download the Win Patch Also use Building on MSVC tutorial to change your mkspecs first. In your Qt folder with command prompt, type:

configure -static -release
and when finished:
nmake sub-src
Following are some errors and their soultions that may be you will get during QT compilation

Error # 1

mingw32-make[3]: Entering directory `C:/Qt/4.2.3/src/corelib'
g++ -x c++-header -c -g -g -Wall -frtti -fexceptions -DQT_SHARED -DQT_THREAD_SUP
PORT -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_BUILD_CORE_LIB -DQT_MAKEDLL -DQT_ASCI
I_CAST_WARNINGS -DQT3_SUPPORT -DQT_MOC_COMPAT -DQT_DLL -I"C:/Qt/4.2.3/include" -
I"C:/Qt/4.2.3/include/QtCore" -I"tmp" -I"C:/Qt/4.2.3/src/corelib/global" -I"..\3
rdparty\zlib" -I"C:/Qt/4.2.3/include/ActiveQt" -I"tmp\moc\debug_shared" -I"." -I
"..\..\mkspecs\win32-g++" -o tmp\obj\debug_shared\qt_pch.h.gch\c++ global\qt_pch
.h
g++: language c++-header not recognized
g++: global\qt_pch.h: linker input file unused because linking not done
g++ -c -include tmp\obj\debug_shared\qt_pch.h -g -g -Wall -frtti -fexceptions -D
QT_SHARED -DQT_THREAD_SUPPORT -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_BUILD_CORE_L
IB -DQT_MAKEDLL -DQT_ASCII_CAST_WARNINGS -DQT3_SUPPORT -DQT_MOC_COMPAT -DQT_DLL
-I"C:/Qt/4.2.3/include" -I"C:/Qt/4.2.3/include/QtCore" -I"tmp" -I"C:/Qt/4.2.3/sr
c/corelib/global" -I"..\3rdparty\zlib" -I"C:/Qt/4.2.3/include/ActiveQt" -I"tmp\m
oc\debug_shared" -I"." -I"..\..\mkspecs\win32-g++" -o tmp\obj\debug_shared\qglob
al.o global\qglobal.cpp
global/qglobal.cpp: tmp\obj\debug_shared\qt_pch.h: No such file or directory
mingw32-make[3]: *** [tmp\obj\debug_shared\qglobal.o] Error 1
mingw32-make[3]: Leaving directory `C:/Qt/4.2.3/src/corelib'
mingw32-make[2]: *** [debug-all] Error 2
mingw32-make[2]: Leaving directory `C:/Qt/4.2.3/src/corelib'
mingw32-make[1]: *** [sub-corelib-make_default] Error 2
mingw32-make[1]: Leaving directory `C:/Qt/4.2.3/src'
mingw32-make: *** [sub-src-make_default-ordered] Error 2
Soultion:
This error will  occur because you are compiling QT with older version of gcc. Please get lastest version from here (Automated MinGW Installer) and compile.

Error # 2 When I compile debug libs for Qt4.3.1 with MinGW, WinXP. It caught my system include path- VC6 and provided the following makefile, needless to say the MinGW failed to make:

(cd F:\Qt\4.3.1\src\winmain && mingw32-make -f Makefile debug mingw32-make[1]: Entering directory `F:/Qt/4.3.1/src/winmain' mingw32-make -f Makefile.Debug Makefile.Debug:116: *** multiple target patterns. Stop. mingw32-make[2]: Entering directory `F:/Qt/4.3.1/src/winmain' mingw32-make[2]: Leaving directory `F:/Qt/4.3.1/src/winmain' mingw32-make[1]: *** [debug] Error 2 mingw32-make[1]: Leaving directory `F:/Qt/4.3.1/src/winmain' mingw32-make: *** [debug-F__Qt_4_3_1_src_winmain] Error 2


Solution :

msvc 6 annoyingly sets the environment variables lib and include and the qt compile picks up on these.

You can tell if these have been configured this way by typing 'set' at a command prompt and you can work around it by making sure you execute:

set lib=
set include=

before you run 'configure'.

Error # 3 UNICODE_STRING' does not name a type

I try configure and compile Qt 4.4.2
Bat I recive error compiling gmake:
In file included from
C:/Lang/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/security.h:3
8,
from
D:\Lang\qt\qt4.4.2/src/corelib/io/qfsfileengine_win.cpp:74:
C:/Lang/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/sspi.h:60:
error: `UNICODE_STRING' does not name a type


Solution

The problem is that UNICODE_STRING is defined in subauth.h which is  not included by security.h prior to including sspi.h.  I've included subauth.h in the attached sspi.h to resolve the issue, but I want to
make sure it doesn't have any nasty side affects.

Please inlcude subauth.h in sspi.h like below.
#ifndef _SSPI_H

#define _SSPI_H
#if __GNUC__ >=3
#pragma GCC system_header
#endif

#ifdef __cplusplus
extern "C" {
#endif

#include <subauth.h>

................
Rest of code of sspi.h.

Error # 4 InterlockedCompareExchange(volatile LONG*, LONG, LONG)' conflicts with
$ make

d:/Qt/4.4.1/bin/qmake.exe -win32 -o Makefile nifskope.pro
make -f Makefile.Release
make[1]: Entering directory `/d/Programs/niftools/nifskope'
g++ -c -O2 -Wall -frtti -fexceptions -mthreads -DUNICODE -DQT_LARGEFILE_SUPPORT -DFSENGINE -DEDIT_ON_ACTIVATE -DQT_THREAD_SUPPORT -DQT_DLL -DQT_NO_DEBUG -DQT_XML_LIB -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I'../../../Qt/4.4.1/include/QtCore' -I'../../../Qt/4.4.1/include/QtCore' -I'../../../Qt/4.4.1/include/QtNetwork' -I'../../../Qt/4.4.1/include/QtNetwork' -I'../../../Qt/4.4.1/include/QtGui' -I'../../../Qt/4.4.1/include/QtGui' -I'../../../Qt/4.4.1/include/QtOpenGL' -I'../../../Qt/4.4.1/include/QtOpenGL' -I'../../../Qt/4.4.1/include/QtXml' -I'../../../Qt/4.4.1/include/QtXml' -I'../../../Qt/4.4.1/include' -I'd:/Qt/4.4.1/include/ActiveQt' -I'release' -I'.' -I'../../../Qt/4.4.1/mkspecs/default' -o release/basemodel.o basemodel.cpp
g++ -c -O2 -Wall -frtti -fexceptions -mthreads -DUNICODE -DQT_LARGEFILE_SUPPORT -DFSENGINE -DEDIT_ON_ACTIVATE -DQT_THREAD_SUPPORT -DQT_DLL -DQT_NO_DEBUG -DQT_XML_LIB -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I'../../../Qt/4.4.1/include/QtCore' -I'../../../Qt/4.4.1/include/QtCore' -I'../../../Qt/4.4.1/include/QtNetwork' -I'../../../Qt/4.4.1/include/QtNetwork' -I'../../../Qt/4.4.1/include/QtGui' -I'../../../Qt/4.4.1/include/QtGui' -I'../../../Qt/4.4.1/include/QtOpenGL' -I'../../../Qt/4.4.1/include/QtOpenGL' -I'../../../Qt/4.4.1/include/QtXml' -I'../../../Qt/4.4.1/include/QtXml' -I'../../../Qt/4.4.1/include' -I'd:/Qt/4.4.1/include/ActiveQt' -I'release' -I'.' -I'../../../Qt/4.4.1/mkspecs/default' -o release/glview.o glview.cpp
In file included from d:/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/windows.h:50,
                 from gl/GLee.h:57,
                 from glview.cpp:43:
d:/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/winbase.h:1663: error: declaration of C function `LONG InterlockedCompareExchange(volatile LONG*, LONG, LONG)' conflicts with
../../../Qt/4.4.1/include/QtCore/../../src/corelib/arch/qatomic_windows.h:393: error: previous declaration `long int InterlockedCompareExchange(long int*, long int, long int)' here
d:/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/winbase.h:1667: error: declaration of C function `LONG InterlockedDecrement(volatile LONG*)' conflicts with
../../../Qt/4.4.1/include/QtCore/../../src/corelib/arch/qatomic_windows.h:395: error: previous declaration `long int InterlockedDecrement(long int*)' here
d:/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/winbase.h:1668: error: declaration of C function `LONG InterlockedExchange(volatile LONG*, LONG)' conflicts with
../../../Qt/4.4.1/include/QtCore/../../src/corelib/arch/qatomic_windows.h:396: error: previous declaration `long int InterlockedExchange(long int*, long int)' here
d:/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/winbase.h:1672: error: declaration of C function `LONG InterlockedExchangeAdd(volatile LONG*, LONG)' conflicts with
../../../Qt/4.4.1/include/QtCore/../../src/corelib/arch/qatomic_windows.h:397: error: previous declaration `long int InterlockedExchangeAdd(long int*, long int)' here
d:/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/winbase.h:1676: error: declaration of C function `LONG InterlockedIncrement(volatile LONG*)' conflicts with
../../../Qt/4.4.1/include/QtCore/../../src/corelib/arch/qatomic_windows.h:394: error: previous declaration `long int InterlockedIncrement(long int*)' here
make[1]: *** [release/glview.o] Error 1
make[1]: Leaving directory `/d/Programs/niftools/nifskope'
make: *** [release] Error 2


Solution: 

(1) Qt\4.4.3\src\corelib\arch\qatomic_windows.h:
#if !(defined Q_CC_BOR) || (__BORLANDC__ < 0x560)
extern "C" {
__declspec(dllimport) long __stdcall InterlockedCompareExchange(long *, long, long);
__declspec(dllimport) long __stdcall InterlockedIncrement(long *);
__declspec(dllimport) long __stdcall InterlockedDecrement(long *); __declspec(dllimport) long __stdcall InterlockedExchange(long *, long);
__declspec(dllimport) long __stdcall InterlockedExchangeAdd(long *, long);
}
#else
extern "C" {
__declspec(dllimport) long __stdcall InterlockedCompareExchange(long volatile*, long, long);
__declspec(dllimport) long __stdcall InterlockedIncrement(long volatile*);
__declspec(dllimport) long __stdcall InterlockedDecrement(long volatile*);
__declspec(dllimport) long __stdcall InterlockedExchange(long volatile*, long);
__declspec(dllimport) long __stdcall InterlockedExchangeAdd(long volatile*, long);
}
#endif
you will see above code in Qt\4.4.3\src\corelib\arch\qatomic_windows.h: file. I modified like  below and it works.

/*#if !(defined Q_CC_BOR) || (__BORLANDC__ < 0x560)
extern "C" {
__declspec(dllimport) long __stdcall InterlockedCompareExchange(long *, long, long);
__declspec(dllimport) long __stdcall InterlockedIncrement(long *);
__declspec(dllimport) long __stdcall InterlockedDecrement(long *); __declspec(dllimport) long __stdcall InterlockedExchange(long *, long);
__declspec(dllimport) long __stdcall InterlockedExchangeAdd(long *, long);
}
#else */
extern "C" {
__declspec(dllimport) long __stdcall InterlockedCompareExchange(long volatile*, long, long);
__declspec(dllimport) long __stdcall InterlockedIncrement(long volatile*);
__declspec(dllimport) long __stdcall InterlockedDecrement(long volatile*);
__declspec(dllimport) long __stdcall InterlockedExchange(long volatile*, long);
__declspec(dllimport) long __stdcall InterlockedExchangeAdd(long volatile*, long);
}
// #endif

I simply commented the above code and it works.