Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

The version of Qt Creator that ships in the repos. can compile Linux executables out of the box. However, it seems like some configuration is necessary to get it to compile Windows applications.

I have the Mingw32 toolchain installed, and I have access to a Windows build of the Qt libraries.

What steps do I need to take to make this work?

share|improve this question

3 Answers 3

up vote 0 down vote accepted

here is a guide for it Installing the Qt libraries into Wine

Now download the Qt SDK and install it into the wine environment. At the time of this writing, we only tested version 4.7.4, but you can grab the latest version from the nokia website. For the sake of compatibility, make sure you download the same version as the one which comes with your Ubuntu version: check it here.

cd /tmp
wine qt-win-opensource-4.7.4-mingw.exe

The last command will launch the installer as if it was on a Windows environment. Do NOT run it as sudo! During the install you will be prompted that MinGW is missing: this is perfectly normal and can be ignored.

After the successful install we need to set the environment variable PATH in Wine, as it, for some reason, is not set automatically by the Qt installer. Simply run:

wine regedit

and browse to "HKEY_CURRENT_USER/Environment". Right click and add a new string value with name "Path". Double click on it to edit and set its value to "c:\windows;c:\windows\system;c:\Qt\4.7.4\bin". Refer to the Wine User Guide for further details on how to set environmental variables.

Defining the cross-compilation qmake environment

Now for the tricky part. Qt programs are usually compiled with qmake, which takes care of setting the right compiler options. For this purpose some specific config files are required for the target platform. We need to create such a config file, tailored for cross-compilation. As a template we will use the win32 config file, so let's make a copy of the related environment first:

cp -Rfp /usr/share/qt4/mkspecs/win32-g++ /usr/share/qt4/mkspecs/win32-x-g++

We have to edit /usr/share/qt4/mkspecs/win32-x-g++/qmake.conf and replace the default compilers gcc and g++ with the cross-compilers provided by the MinGW package, along with other options. Ours looks like this:

# qmake configuration for win32-g++
# Written for MinGW

TEMPLATE        = app
CONFIG          += qt warn_on release link_prl copy_dir_files debug_and_release debug_and_release_target precompile_header
QT          += core gui

QMAKE_EXT_OBJ           = .o
QMAKE_EXT_RES           = _res.o

QMAKE_CC        = i586-mingw32msvc-gcc
QMAKE_LEX       = flex
QMAKE_YACC      = byacc
QMAKE_CFLAGS_YACC   = -Wno-unused -Wno-parentheses

QMAKE_CXX       = i586-mingw32msvc-g++
QMAKE_CXXFLAGS_EXCEPTIONS_ON = -fexceptions -mthreads

QMAKE_INCDIR        = /usr/i586-mingw32msvc/include/
QMAKE_INCDIR_QT     = /home/matteo/.wine/drive_c/Qt/4.7.4/include
QMAKE_LIBDIR_QT     = /home/matteo/.wine/drive_c/Qt/4.7.4/lib

QMAKE_RUN_CC        = $(CC) -c $(CFLAGS) $(INCPATH) -o $obj $src
QMAKE_RUN_CC_IMP    = $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<
QMAKE_RUN_CXX       = $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $obj $src

QMAKE_LINK      = i586-mingw32msvc-g++
QMAKE_LINK_C        = i586-mingw32msvc-gcc
QMAKE_LFLAGS        = -mthreads -Wl,-enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mwindows
QMAKE_LFLAGS_CONSOLE    = -Wl,-subsystem,console
QMAKE_LFLAGS_WINDOWS    = -Wl,-subsystem,windows
QMAKE_LFLAGS_DLL        = -shared

QMAKE_LIBS_CORE         = -lkernel32 -luser32 -lshell32 -luuid -lole32 -ladvapi32 -lws2_32
QMAKE_LIBS_GUI          = -lgdi32 -lcomdlg32 -loleaut32 -limm32 -lwinmm -lwinspool -lws2_32 -lole32 -luuid -luser32 -ladvapi32
QMAKE_LIBS_NETWORK      = -lws2_32
QMAKE_LIBS_OPENGL       = -lglu32 -lopengl32 -lgdi32 -luser32
QMAKE_LIBS_COMPAT       = -ladvapi32 -lshell32 -lcomdlg32 -luser32 -lgdi32 -lws2_32
QMAKE_LIBS_QT_ENTRY     = -lmingw32 -lqtmain

#!isEmpty(QMAKE_SH) {
    MINGW_IN_SHELL      = 1
    QMAKE_DIR_SEP       = /
    QMAKE_QMAKE     ~= s,\\\\,/,
    QMAKE_COPY      = cp
    QMAKE_COPY_DIR      = xcopy /s /q /y /i
    QMAKE_MOVE      = mv
    QMAKE_DEL_FILE      = rm
    QMAKE_MKDIR     = mkdir
    QMAKE_DEL_DIR       = rmdir
    QMAKE_CHK_DIR_EXISTS = test -d
#} else {
#   QMAKE_COPY      = copy /y
#   QMAKE_COPY_DIR      = xcopy /s /q /y /i
#   QMAKE_MOVE      = move
#   QMAKE_DEL_FILE      = del
#   QMAKE_MKDIR     = mkdir
#   QMAKE_DEL_DIR       = rmdir
#   QMAKE_CHK_DIR_EXISTS    = if not exist


QMAKE_IDL       = midl
QMAKE_LIB       = ar -ru
QMAKE_RC        = i586-mingw32msvc-windres
QMAKE_ZIP       = zip -r -9

QMAKE_STRIP     = i586-mingw32msvc-strip
QMAKE_STRIPFLAGS_LIB    += --strip-unneeded

Tip: if you encounter any problems while setting up the config file, have a look at the script which comes with this tutorial, which automates every single step.

Bonus: set up a cross-architecture environment

Many new machines are built with a 64-bit architecture. If you are developing on one of these, chances are that you also want to produce 32-bit binaries that can be run on older computers. This is easily achieved, because the Ubuntu package provides both versions of the libraries. There is only one line to be added to the config file, do it by running:

echo "QMAKE_LIBDIR_QT         = /usr/lib32/" >>/usr/share/qt4/mkspecs/linux-g++-32/qmake.conf

As for the windows environment, Nokia only provides 32-bit versions of the Qt libraries, which should already be compatible with both architectures. The setup we presented will already produce this kind of executables. If you want to optimize the binaries for 64-bit environments there are a few options:

Acquire a payed license for Qt from Nokia. Their support desk will then provide 64-bit binaries upon request.
Download the source code from the Nokia website, and compile Qt yourself for 64-bit environments.
Download and install unofficial (untrusted!) binaries you might be able to find in the Internet.
share|improve this answer

I found a much easier solution: simply install Qt Creator under Wine.

I had to use winetricks to get the VC++ 2008 runtime files installed first but after that, it worked perfectly.

share|improve this answer

Disclaimer: I'm not an avid Qt Creator user, so I may be wrong.

If Qt Creator supports custom compilers, try setting the mingw compiler as one, and setting the library paths to mingw's include directories (along with the appropriate paths for the windows headers).

This method has worked for me in the past on other IDEs (such as codeblocks), so I'm going on a limb and guessing it will for Qt Creator as well.


After doing some searching around in Qt Creator, I'm not too sure if this is possible.

share|improve this answer
But where do I set this 'custom compiler'? I know what you're talking about since I used to do the same thing in Code::Blocks. But Qt doesn't seem to offer this feature. –  Nathan Osman Apr 29 '11 at 23:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.