Using the Qt OpenGL example program we introduced in the labs.
You can find it at: /home/jungle/pj/www/453/box/test NOTE: newly commented globjwin.cpp and main.cpp
(This file will most likely remain unchanged for most of your 453 carreers.)
Play with Qt and some of the widgets it provides.
A widget can be thought of as a Window Gadget. For example: the window itself, a slider, button, text box, etc.
You should reference the documentation for specifics on parameters.
Be aware of the order of widgets. Their placing in the code in this example has a relationship with their placing in the window.
![]() |
|
|
|
![]() |
|
Main
The main() function is used to perform some initialisation before
control is passed to Qt. Explanation of code: The QApplication class controls the program flow. It is required
for any Qt application. argc and argv are C/C++ features. They are the number of command
line arguments and the array of command line arguments
respectively. GLObjectWindow is our class that contains all of the Qt GUI
specific code. It opens a window that has a menu, some sliders and an
openGL canvas in which to draw our openGL objects.
w.resize(); sets the initial size size of the window.
a.setMainWidget(&w) says that the main widget for this Qt
application (a) is w the GLObjectWindow.
It is possible to have a widget that is not visible at the start of
the program, or indeed can be visible or hidden during different parts
of a program. We want to be able to see the main widget which is our
GLObjectWindow, so we have to show it. Bear in mind that widgets are
never visible when they are created, you must show()them for them to
be visible.
This is where main() passes control to Qt. This is the main
loop. This is the point of return when the program exits.
Useful References
Qt Reference Documentation
The Qt tutorials
Contact me
int main( int argc, char **argv )
{
QApplication a(argc,argv);
GLObjectWindow w;
w.resize( 400, 350 );
a.setMainWidget( &w );
w.show();
return a.exec();
}
QApplication a(argc,argv);
GLObjectWindow w;
w.resize( 400, 350 );
a.setMainWidget( &w );
w.show();
return a.exec();
email: pj@cpsc.ucalgary.ca
Tel: (403) 220 7041.