Creating a Visual Studio Console Application That Uses Qt Graphics
Using Qt graphics within a Visual-Studio console application is a non-standard use of the Qt software. The Qt tool qmake
doesn't support the creation of console applications, so to use Qt graphics in a console application requires that you create your console application using Visual-Studio and then link to the required Qt graphics libraries. The essential steps are
- If you didn't keep the library you created in Assignment 5 (b), create a QtConsoleGraphics library using the qmake tools followed by nmake. Details
- Create a standard Win32 console project and add your project files and set the required paths and library information as needed.
- The additional program settings that are required to use Qt console graphics in a console project consists of
- specifying information associated with the QtConsoleGraphics library
- Add to your include path the location of the QtConsoleGraphics header files. This will most likely be the sub-directory where you downloaded the QtConsoleGraphics header repository in your course directory.
- Add the location of the QtConsoleGraphics library to Linker/General/Additional Library Directories field (screenshot)
- Add QtConsoleGraphics.lib to the list of additional linker input dependencies (screenshot)
- specifying information associated with the Qt libraries
- Add to your include path the location of the Qt package header files. These will be located in the include subdirectory of the Qt code installation. On the PIC system the location is C:\Qt\4.4.3\include
- Add the location of the Qt package support libraries to Linker/General/Additional Library Directories field (screenshot) This is the lib directory of the Qt code installation. On the PIC system the location is C:\Qt\4.4.3\lib.
- Add QtCored4.lib and QtGuid4.lib to the list of additional linker input dependencies (screenshot).
Note: if you are using release versions, then you would specify the non-debug versions QtCore4.lib and QtGui4.lib. If you are unsure what versions you have you can go the the location of the Qt installation and inspect the contents of the lib directory.
Screenshot of sample Assign6 entries for Linker/General/Additional Library Directories
Screenshot of sample Assign6 entries for additional linker input dependencies
- When your program is run from the IDE a console should appear allowing console input and output. If a graphics window is called (e.g. the frame() method of the graphics driver is invoked) then the graphics window may appear behind other windows. You can bring it to the front by selecting the icon for it from your toolbar or by cycling through your open windows using an Alt-Tab combination.
- For Linux/Unix users. To create a console Qt application one follows essentially the same process as for Visual Studio users. First,build the QtConsoleGraphics library (using make instead of nmake). Then create a standard console application, as in previous assignments, but with the additional specification of the include paths, library locations, and library names for the QtConsoleGraphics library and Qt software library.
Details on building a QtConsoleGraphics support library: Download the QtConsoleGraphics repository from https://www.math.ucla.edu/~anderson/157support/. Open up a Visual Studio Command Prompt window, and then cd to the QtConsoleGraphics directory and execute the commands
qmake -project -t lib "CONFIG += staticlib"
qmake
nmake
The result of this process should be a file QtConsoleGraphics.lib
in the debug subdirectory of QtConsoleGraphics. This implicitly assumes that you downloaded the files to a directory QtConsoleGraphics.