Qt4 on Windows

From qtnode

Jump to: navigation, search

This short guide will show you how to get Qt to work on your Windows system using the MinGW tools. If you are interested in using the MS Visual Studio compiler, check out: Qt4 with Visual Studio

First step is of course to Download Qt. If you want to get going as quickly as possible, download the precompiled version of the setup. You will still need MinGW installed to compile your programs. If you want to compile Qt yourself, you can do this as well.

Setting up the precompiled version of Qt

  1. Run the installer
    If you are prompted to download MinGW automatically, try it. Many people have reported that this does not always work. If it fails, you will have to install MingW yourself.
  2. Run the demos to make sure everything has installed correctly. Go into the program group created for Qt and run the "Examples and Demos" shortcut.
  3. Open up a console using the shortcut named "Qt 4.x command prompt". This will ensure your path points to the proper bin directory and you will should be able to start using Qt right away. Make sure MinGW (namely mingw32-make) is also in your path.
  4. Try out a Hello World program.

Compiling Qt from Source using MinGW

  1. Unzip the source in a directory of your choosing. C:\Qt\4.x\ is a logical choice.
  2. Make sure you have MinGW installed.
    Qt's configure.exe will look at the INCLUDE and LIB environment variables. You'll want to make sure you've set these with the paths to include and lib for mingw.
  3. Go into the directory where you unzipped Qt and run configure.exe --help This will tell you all the compile time options you want. Normally, you would want -debug-and-release and -platform win32-g++. When you have decided you are ready, run the command:
    c:\Qt\4.2.2>  configure.exe -debug-and-release -platform win32-g++
    Note, that if you are trying to build static versions of the libraries (i.e. you don't want to deal with DLLs and want huge standalone binaries) take a look at Building static.
  4. After the configuration is complete, you are now ready to make the libraries and executables:
    mingw32-make
    If you encounter an error check out Common problems.
  5. Hint: You can speed up the compile by losing the examples/demos directories with
    c:\Qt\4.2.2>mingw32-make sub-src
    Of course you won't have any of them then, but it will take much less time to compile
  6. Try out a Hello World program.

Setting up MySQL for building Qt with MinGW

  1. Run the installer for MySQL. (The 'Community Edition - Windows Essentials' installer includes step 2 below. You need to select the custom option to install the c/c++ header files. It is also recommended to install mysql to c:\mysql5 for example instead of the default "c:\program files\mysql\mysql server 5.0\..." as the long path name has to be accessed by DOS 8.3 filenames (eg c:\prog~1\) by mingw).
  2. Download and extract the src code.
  3. Mysql uses .dll's and .lib's that are incompatible with MinGW's linker. You will need to make a libmysql.a file for MinGW. To do this you will need the mingw-utils package. After you extract the package, copy reimp.exe to your MinGW\bin directory that you specified in your path. (same place dlltool.exe lives)
  4. Then you will need to use the command prompt and go to your \path\to\msyqlinstall\lib\opt directory.
  5. Run these two commands
    reimp -d libmysql.lib
    
dlltool -k -d libmysql.def -l libmysql.a
  1. Qt needs to know what library to link to as well as where it and the header files are located.
  2. Add these parameters to your configure.exe command
    -qt-sql-mysql -l mysql -I c:\path\to\mysqlsrc\include -L c:\path\to\msyqlinstall\lib\opt
  3. And you're ready to build!
Personal tools