Creating a QT project with an OpenGL window in Windows with MS Dev Studio 6.0 & C++.

  • Install QT! You can grab QT from TrollTech's site by filling out their evaluation form found here. Get version 3.2.0 if you can. Installation is pretty easy, just install like normal & then follow the instructions in the QT readme file. The most important steps from this are:
    1. Start Visual Studio if it isn't already running.
    2. Click Tools|Customize to launch the Customize dialog. 
    3. Click the Add-ins and Macro Files tab.
    4. Ensure the checkbox to the left of the "QMsDev Developer Studio-Add-In"
       add-in is checked.
    5. Click Close. 
    When this is finished your developer studio should look like this:

    The most important part is that you should have 7 new green icons in the top right corner.

  • UPDATE - In the UG graphics lab the machines have version 3.2. However it's very difficult (perhaps even impossible) to get this through the QT web site. There's two options, the first is that Trolltech has an official, open source version of Qt 4.1. I've never used version but it definitely could be good. The other possibility is that there are sourceforge projects that have something equivalent to Qt version 3.

  • Make certain you have OpenGL installed on your computer. If you're not sure that is has been installed try searching for "opengl32.lib"; if OpenGL has been installed it should be found someplace like "C:\Program Files\Microsoft Visual Studio\VC98\Lib". They come with Deverloper Studio so you should have them unless you've done something naughty, like chosen not to install these files. If this is the case you can get the OpenGL files, etc from Microsoft here.

  • Last but not least, make certain your system variables have been set up correctly. Often if you've tried to install QT several times this is not the case. So what you need to do is go into control panel -> system -> advanced and ensure that your path includes C:\whereeveryouinstalledqt\qt3.2.XXXEvaluation\bin and that you have an environment variable called QTDIR that points to C:\whereeveryouinstalledqt\qt3.2.XXXEvaluation. Added Feb 9 - JDB
  • Create a project. Do this in Deverloper Studio by clicking the "New QT Project Button" . This brings up the following dialog to specify the details for your projects.

    Give your project a name & specify the directory you want it in. For application type select "main window" if you want to be able to have a menu or MDI support. If you don't need this select "dialog".
    When you hit okay two things happen. The first is that a project with 5 source files and 2 headers files is created in MS Developer Studio. The second is that QT designer is loaded with your form.

    The new form first loaded by QT designer.

  • Now we need to create our OpenGL widget. You can use any of your old OpenGL widgets that you used in LINUX for this. For example, you could use the widget I gave in my QT designer tutorial. To follow along with this tutorial use this example widget's files: glexamplewidget.h and glexamplewidget.cpp. Take the .cpp and .h files and copy them into your project directory.
    Go to developer studio and add these two files to your project.


  • Now here is the tricky part. Open glexamplewidget.h in dev studio and then click so that glexamplewidget.h is highlighted in the workspace/fileview window. Now click the moc button . If you did this step right you should now have a file called moc_glexamplewidget.cpp in your project.

    If this didn't work keep trying until it does because your project won't work until you have an moc file for your widget. As a side note, if you're going to add more than one gl widget you will need an moc file for each different widget.

  • Our next step is to switch back to QT Designer & create a new custom widget. Do this by going to Tools->Custom->Edit Custom Widgets.

    Now click the "New Widget" button & fill in the definition. Remember that capitalization does make a difference. If you browse to select "glexamplewidget.h" please remove the absolute path and specify "local" as is shown below.

    The reason for this is it makes it easier for others(aka your TA) to compile & run your program from another location. Use the signal & slots tabs on this dialog window to add these feature to your widget as you need them. Click "Close" to return to your form. Now select "Custom Widgets" in the Toolbox & click on GLExampleWidget. Now place the widget on your form.


  • Our last step is to get the project to compile. Click "save" and then switch from QT Designer back to Developer Studio. Our task now is to add the necessary OpenGL libraries to our compilation. Go to Project -> Settings and then select the link tab. In the Object/library modules text box add "opengl32.lib" and "glu32.lib", and then click "Ok".

    Now press Ctrl-F5 to compile. There's your QT designer project in windows.

  • That's got your started (the hardest part), see my QT designer demo if you are unsure of how to use designer, it's pretty much the same as in LINUX.

Hint
If you like to be able to see your standard output (i.e., printf, cout) then in developer studio go to Project -> Settings and scroll through the "Project Options" text box until you find "subsystem:windows", change this to "subsystem:console", click "Ok" and then recompile. Your program will now have a console screen in the background that will show all your output.

If you have any questions, problems, or comments please email me (brosz at cpsc.ucalgary.ca).

John Brosz, January 10, 2005