QT Info
QT Info
QT Info
Background and documentation You can read about the evolution and features of the Trolltech Qt framework at these links which you should look at in this order. Big Picture: http://www.trolltech.com/pdf/whitepapers/qt33-whitepaper-a4.pdf Technical Stuff: http://doc.trolltech.com/3.2/index.html Tutorial: http://doc.trolltech.com/3.0/tutorial.html The documentation about classes, signals, and slots is ovewhelming but you should scout around and see how much you can absorb about writing and running Qt applications. I will describe how to build Qt apps in detail in class and lab so for now figure out what you are going to need to learn in order to build your GUI application. Using Qt on the Linux machines on campus The Qt tools installed on the Linux machines are sufficient to do all our work in building a GUI for our Kalah game. We can edit our files much like before and use the convenient qmake and make commands to build our applications. A Qt application, something like hello or hello.app, is a file which can be (double) mouse clicked and it brings up a window inside which we see widgets (buttons, sliders, images, etc) that inhabit the window content region. Our task is to learn enough about Qt that we know how to define, position, and control these window inhabitants to play a Kalah game for the user. Building Qt projects Each Qt project, including source files, compiled application, etc, must be contained in a single folder. To handle the complex compilation needed for the various libraries, sources, etc, we use a standard Unix tool called make which contains the specific compiler options, dependencies among the various source and object files, and so forth. Since Qt classes add an additional layer of complexity, Trolltech has provided a Meta-object compiler, or moc, that builds the graphics libraries in a consistent manner for us. They also provide a multipurpose tool called qmake used to create a project file, with extension .pro, which wraps all our file dependencies into one file which is then used to create a Makefile which can be normally read by make. Sounds confusing but is pretty simple in actual use. You will also need to add qmake to your PATH environment variables so you can avoid using its entire path name each time you invoke it. I cover that after this example of using qmake. For an example using qmake, suppose I have a single file main.cpp, which contains my entire Qt program, located in folder kalah. To build your application file kalah, simply type these lines: qmake project (Creates a project file based on the includes found in main.cpp) qmake (Creates a file called Makefile which make will consult during compilation) make (This does the actual compilation and displays error messages, etc) Assuming no errors are found during compilation, in your folder you will now find an application called kalah you can run as usual and it will display the window and contents of your application. Note: on Macintosh, you can double click in the Finder or use the command open kalah.app to start the application. Adding to our PATH and other environment variables in Linux The application qmake is found in the /usr/lib/qt3/bin directory so you should add its directory path to your PATH environment variable so you dont have to use the full directory path each time you invoke qmake. To do this, use nedit, or other editor, to edit the file named .profile found in your home directory. Append these lines to your current .profile
QTDIR=/usr/lib/qt3 PATH=$QTDIR/bin:$PATH MANPATH=$QTDIR/man:$MANPATH LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH export QTDIR PATH MANPATH LD_LIBRARY_PATH Save your .profile file, close your session and login again (a quick way to record environment variable changes) and you can now simply use the qmake commands as shown above to build your Qt applications inside any directory. NOTE: If you are using Qt on Mac or Windows, consult the documentation in INSTALL which tells you how to modify your shell .profile or .login accordingly. Using Qt on your own computer Note that you can download and install the various free versions of Qt on your own machine if you wish. Note we will be using version 3.3 of Qt for our examples in class so you man want to install version 3.3 to be consistent with our use and examples. The instructions for installation found at http://doc.trolltech.com/3.3/installation.html are fairly clear but compiling all the various libraries takes a couple of hours and some close reading of the instructions to avoid having to start over. If you have trouble, let me know and I will try to provide suggestions on installation problems. We have Visual C++ for Windows if you wish to do the Windows version. The gcc compiler comes with XCode for the Macintosh which you should install BEFORE you install Qt. Starting to program in Qt Qt comes with a large collection of examples which provides far too many source files to read and build in the time we have available so we will concentrate on just a few examples together with code from the tutorial. All the examples are found in the directory /usr/lib/qt3/doc/examples. You can copy any or all of these example directories over to your home directory and try them out to see what is available in Qt. Each comes with a precompiled application so you can simple run each one and see what it does. I will be using some of the tutorial code also supplied by Trolltech as a way to build up to our Kalah game application. You should locate and copy the tutorial folder found at /classes/cs226/s06/tutorial into a convenient place in your home directory. You can find an explanation of all the tutorials at http://doc.trolltech.com/3.0/tutorial.html. Working through the tutorials is a useful way to get acquainted with the graphics hierarchy and signals/slots mechanism. NOTE: If you wish to start from scratch for each tutorial folder, just delete the .pro and Makefile files in each folder and rebuild the application as described above. Additional references There is one standard book on Qt 3 which I will leave in the computer lab which you can also consult if the need arises.