The daily ramblings …

HOWTO install Qt and Coin3D on Win32

Posted in Programming by akamal on February 13, 2007

Merging C++ with 3D visualization is always a big issue to most people, especially because standards don’t simply exist, and no single GUI library that corresponds seamlessly with 3D library. Some might prefer open source solution, but this usually requires him (or her) to put up with cumbersome tasks of compiling, building, error detection, never-ending problems with no solution.

I deal with lots of 3D development especially since I am required to come up with scientific visualization and interpretation of data. I had all sorts of trouble initially when trying to build one integrated approach. Well, I am going to write here a one in all documentation on how to install QT, Coin3D using only free software, yes you heard me, you don’t have to fork out a single cent, save your monthly internet bill.

So, if you’re interested on development of QT and 3D graphics, open inventor-like approach, this is the right place for you to start!

UPDATE 3/3/2007
I have included installation guide on qwt (QT widgets for Technical Application), especially for those of you who wants to use qt for scientific applications. So far, I have also modified this article, where the previous ones did not include things like set up of environment variable QMAKESPEC. So, happy installing!


What you need to download are listed below:

Software Library Version File Name Website URL
Qt 4.2.2 (source)
Coin 3D 2.4.5 (source)
SoQt 1.4.1 (source)
Q../Free 4.2.2
Visual C++ 2005 Express Edition 2005 msvc2005.exe
Microsoft Platform SDK 2003 SP1 (around 13 files)
QWT 5.0.1


First make sure everything is installed / unzipped under 1 directory, e.g: D:\devel\. So you will deal with stuff under one roof. It’s not really necessary, but I find it rather easy to manage.


Use the Visual C++ 2005 command prompt; instead of the normal command window cmd.exe (This will be available once you install Visual C++ 2005). Reason for this? We want to use the nmake feature.

All the steps listed below MUST be strictly performed in its outmost respect! Do not miss even 1 step, as failure to do so will cause you headache and tendency to throw things to the front yard! You’ve been warned!


Install Visual C++ Express Edition first. Just normally follow through the steps and there’ll be downloads to be done while installing.

When the VC Express setup is complete, install Microsoft platform SDK next. Depending on the file type you download, you will either have lots of .cabs file with extract.exe, or simply just an ISO file. I recommend downloading the one with lots of .cabs file (Make sure you download everything listed in that webpage).

If you download the .cabs files, then open up msvc2005 command prompt and type

>> Psdk-full d:\devel\msdk

Note: You must set Internet Explorer to default web browser as the installation requires activeX.
Read the instruction provided by Microsoft Platform SDK readme website, and install all SDK! That means when the setup page asks you what to install, just click Windows SDK, by default, all SDK will be installed.

After installation of MSDK is completed, you’re required to tweak a little on msvc2005 settings. Read through below:

Launch Microsoft Visual C++ Express Edition.
Click Options > Projects and Solutions > Visual C++ Directories:
Add the lines below:
Executable files: d:\devel\msdk\Bin
Include files: d:\devel\mdsk\Include
Library files: d:\devel\msdk\Lib

Update the corewin_express.vsprops file based on instruction below:

Open the file which resides in d:\devel\vc_express\VC\VCProjectDefaults\ corewin_express.vsprops
Change the string that reads:
AdditionalDependancies=”kernel32.lib” to
AdditionalDependancies=”kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib
shell32.lib ole32.lib oleaut32.lib uuid.lib”


Unpack / unzip the qt-4.2.2-src file to a directory, e.g d:\devel\ so it will become d:\devel\qt-4.2.2 .

Then unzip the qt patch file ( and put all the content inside qt-4.2.2 folder.

Run installpatch42.bat by clicking on it, or typing it at the command line.

Now inside folder qt-4.2.2, from the vc2005 command prompt, type qconfigure.bat msvc2005 (DO NOT use the provided configure.exe file at all)

Just press yes to everything, sit back and relax while the installation proceeds.


Right click at My Computer > Properties > Advanced > Environment Variables

Add new variables QTDIR and QMAKESPEC under user variables:

Variable name : QTDIR
Variable value : d:\devel\qt-4.2.2

Variable name : QMAKESPEC
Variable value : win32-msvc2005

Edit path variable by adding below value:

Configure msvc2005 settings, by aunching msvc2005, then click Option Tools > Options dialog box.

Add all directories listed under QTDIR\include to Include files. (YES, ALL!)

…. and so on

Add all directories listed under QTDIR\lib to Library files.


Unzip to let’s say, d:\devel\Coin-2.4.5 .

Create an environment variable COINDIR with value d:\devel\Coin-2.4.5 (similar to method in STEP 3).

Now go to d:\devel\Coin-2.4.5\build\msvc8, and launch Coin2.sln (a vc solution file). Visual C++ 2005
will be launched with the solution / project opened.

Click Build > Configuration Manager under the toolbar. Then change the value in Active Solution Configuration to DLL (RELEASE).

Now click on Build > Build Solution. Just wait for it to compile and complete.


Unzip SoQt-1.4.1 to let’s say d:\devel\SoQt-1.4.1 .

Inside folder SoQt-1.4.1, go to \build\msvc8\ and launch soqt1.sln (a vc solution file). Visual C++ 2005 will be launched with the solution / project opened.

Click Build > Configuration Manager under the toolbar. Then change the value in Active Solution Configuration to DLL (RELEASE).

Now click on Build > Build Solution. Just wait for it to compile and complete.



Use msvc2005-command prompt to create project qwt file. Do this by typing :
>> // Change directory to qwt dir
>> qmake
>> nmake

If you followed everything correctly up till now, then you should not have any problem. Notice that several files will be built under qwtdir\lib, namely qwt.dll and qwt.lib.


Here are the basic steps listed below:

Create a qt file, maybe named qt_test.cpp and then store it in a newly created project directory, let’s say directory qt_test.

Next, launch msvc2005-command-prompt, go to the directory which contains the file.

>> qmake -project -t vcapp
>> qmake

This will generate a .vcproj file, which is a project file for msvc2005. You can then open it, and run and work in msvc2005.


If you have built it, then proceed with adding qwt path for /lib and /src to msvc2005.

To do that, in msvc2005, click Tools > Options > Projects and Solution > VC++ Project Directories and add below values:

Include Files : qwtdir\src
Library Files : qwtdir\lib

Now create or load a qwt based project, and when you already done that, add preprocessor definition QWT_DLL to your project’s preprocessor list. To do that, follow below:

Click Project > project properties > Configuration Properties > C/C++ > Preprocessor. Add QWT_DLL to the list of Preprocessor Definitions.


C++ : I/O Streams – Output Formatting

Posted in C++ General by akamal on February 12, 2007

Creating a clean formatted data output is a common programming requirement. Take note however that output formatting requires the use of iomanip.h file, so don’t forget to include it. Anyway, listed below is a collection of tricks to use in C++.


C++ : Static

Posted in C++ General by akamal on January 26, 2007

Static data types can be accessed without the instantiation of the class in C++. Applicable for static functions too. A typical use of static members is for recording data common to all objects. E.g: We can use static data to record the number of objects created.

To access static member, we uses ::(scope resolution) operator. An example is shown below:

01#include <iostream>
02using namespace std;
04class Circle
07	// Initially declare radius as type double and static
08	static double radius;
10	Circle() {} // constructor
11	static void setRadius(double var)
12	{
13		radius = var;
14	}
15	static double getRadius()
16	{
17		return radius;
18	}
19	static double getArea()
20	{
21		return radius * radius;
22	}
25double Circle::radius = 30;
27int main()
29	Circle circ;
30	cout << "Circle 1 radius is : " << Circle::getRadius() << "n";
31	// object circ can also access static method getArea
32	cout << "Circle 1 area is : " << circ.getArea() << "n";
33	Circle::setRadius(50);
34	cout << "Circle 1 radius is now : " << Circle::getRadius() << "n";
35	cout << "Circle 1 area is : " << Circle::getArea() << "n";
36	system("PAUSE");
37	return 0;

From the example above, we don’t need to instantiate the class to access static method “method1”. So, that’s the plain use of static.

Remember the rules of thumb below:

1 – Static members can be called even when no instantiation of class is made. Normal members of class (non-static) can only be called when an object is instantiated out of the class.

2 – Static member / funcntion cannot have access to ‘pointer of the’ class. Meaning that pointer to a class will have its own members, and the static member won’t have access to that.

3 – Static member function cannot be declared virtual, while non-static member can.

4 – Static data members must be defined out side of class definition, because they don’t belong to any specific instance of the class.

01class X
04	static int i;
06// definition outside class declaration
07int X::i = 0;

5 – Static member functions get defined in the class and so should static member variables.

C++ : Methods of Object Instantiations with Classes

Posted in C++ General by akamal on January 16, 2007

When it comes to programming, the best method to learn is by digging up codes from existing source codes, but question remains, how do you learn by looking at thousands of lines of codes? Well firstly, you have to get your basics right.

To recap, Classes and OOP are the main feature provided by C++. With classes, you’d be able to expand your built codes for other future needs, or simply to tackle similar problems by re usability. The purpose of this article is not to look at classes (well not now), but rather a quick peek on the styles of code-writing when instantiating / using classes. Remember that the concept of class is strongly linked to pointers, especially in C++. So you might want to get a brush-up on it first. Look it up here.

Fundamentally, there are 2 styles when writing class instantiations.

  1. The first style assigns a variable with the instantiation of the object itself (as seen in type A).
  2. The second, goes for a more versatile approach by using a variable to store the address of the created object (type B).

type B:

1// We assign a variable named window in line 9. 
2// Its type is not int, char or whatever, but instead it is an 
3// object of class QWidget.
4// To access its properties, we use "." to access its method,
5// as seen in line 10 ---
6int main(int argc, char * argv[])
8	QApplication app(argc,argv);
9	QWidget window;
11	return app.exec();

type B:

1// here, we initially declare a pointer named window 
2// which is of type object. Variable window be allocated in the 
3// memory with no value. Next, we assign the window variable to the 
4// address of the QWidget object just created (new QWidget creates an object).
5// To access its properties, we use "->", known as throwing at, 
6// to access method show() as seen in line 6.
7int main (int argc, char * argv[])
9QApplication app(argc,argv);
10QWidget *window;
11window = new QWidget;
13return app.exec();

Between the 2, there’s aren’t many differences generally, and certainly no pros/cons that I know of. But just to get some people accustomed to the style of writing, one should be aware that class instantiation can be done in 2 ways, as explained above.

C++ : The Concept of Pointer

Posted in C++ General by akamal on January 16, 2007

I was doing my normal programming routine today, when halted for request on ad hoc pointer tutorial by some of my team members. The 1 hour & 30 minutes tutorial spoke for itself, seeing how hard it is for newcomers to grasp the concept.

Throughout the session, questions bombarded ranging from “why the need to pass between functions” to “how important as to store address of a var”? and so on.

So I’ve come up with this small article on this, just a reminder to those who’s so regularly confused with the concept, I know I do.

When programming for software requiring large design, there’ll be hundreds, literally thousands of codes meddling in functions here and there. Especially on a critical / memory heavy s/w, unnecessary usage of memory is certainly a thing to avoid.

The use of pointer allows programmer to keep on using the same variable, WITH the same memory location, passing it to any external functions so as long it requires.

A safe practise of programing always involves pointers, especially in C++. Since we do not have the luxury of automatic memory management, as Java does, those who codes in C++ must always keep in mind on variable allocation and de-allocation (aka deletion).


& is a reference operator. Also means “address of variable to point to”
* means “is a dereference operator. Also means value pointed by the variable”


To understand what the 2 above means, please have a look at the codes below. No point dwelling on lengthy explanations, right? I’d better kick it off with codes review! Let’s begin..

Ok, in line 1 you have a variable var1 of type, say, int. var1 is then assigned the value of 25. Next, you declare

int var1 = 25;
int *var2;
var2 = &var1;
cout << var2;
cout << *var2;

1 int var1 = 25;

var1 = 25; // var1 hold the value 25 in some memory address, say address 1000
2 var2 = &var1; // var2 stores the address of var1, so when typing …
3 cout << var2; // you would get the address of var1, which is 1000
4 var3 = *var2; // now var3 will take the value pointed by var2
5 // var2 has address 1000, and value pointed by address 1000 is 25

The funny thing is a lot of people may understand this concept through books and tutorials, but
when it comes to “real” programming, they’d be perplexed with the way values and address are passed all

I say, that the only way to fully grasps this concept, is to practice regularly with pointers, yeah.

QT : Signals and Slots Mechanism

Posted in QT by akamal on January 16, 2007

One great feature installed inside Qt is the signal and slot mechanism. It’s specially developed for event driven software approach, where no single use case dictates the flow of the software. This feature indeed is central to the whole of Qt concept, which probably made it different to other frameworks.

Signals and slots primarily allows communications between objects. Just like in any other GUI programming, when we change / execute a widget, we often want another widget to be notified. Beneath the concept, we want the objects to ba able to communicate with one another.

When a user clicks the close pushbutton, we’d probably want the mainWindow to close, by calling a close()

Now, for most frameworks, (wxwidget, fltk, win32) the only way to achieve this is to use callbacks, basically a pointer to functions. Based from my experience, callbacks inherits 2 fundamental flaws, firstly they are not type safe, meaning that we can never be certain whether the processing function
will call the callback with correct arguments.

Secondly, a callback is strongly linked to the calling function since the processing function must know which callback to call. In large software development, things can go complex when there’s too many callbacks to call.


An example syntax of signals and slots in Qt is shown below:
QObject::connect(&button_1,SIGNAL(clicked()), &application(quit()));

Like the name says, button_1 is given a signal flag, in the form of a click. When the signal is executed, the application will recevie instruction to respond to the signal, by quitting.

QT : GUI Toolkit Review

Posted in QT by akamal on January 16, 2007

I’ve had my hands on most C++ GUI toolkit available in the market so far, from OSS oriented products like wxWidgets, FLTK, fox toolkit to the commercial ones such as QT, and not forgetting those savvy yet difficult-to-implement GUI libraries, win32 and mfc.

Well, It doesn’t take a rocket scientist to realize, being resource short on mapower, concludes me to
axe both win32 and mfc, due to the amount of commitment need to be thrown at.

So, of all toolkits available, 2 are on my mind. Qt and wxWidgets. I have been an avid fan of wxWidgets all
these while, having at least 50% of previous UI work built using it, but I have to say of recent, the features and hype with Qt programming struck me.

One central feature of QT is in the dealing of object communication, signal and slot mechanism. It’s so
flexible and limitless, where usually with callback routines, you can only call a function (callback)
from a processing function, but with signals+slots, chains of events can be constructed with a single

Plus, just like wxWidgets, there are so many utility classes provided by Qt, and since I am involved heavily in 3D graphics development for scientific interpretations, qt’s support for 3D through openGL plus its wrapper framework to Coin3D library, certainly gave a plus point.

The best thing in Qt is of course it’s cross-platform assurance, since qt doesn’t take on native widgets
when drawing GUI, instead it is built on its own. So, if I am ever required to deploy an app on linux, no / minimum coding is only required.

I’m currently in process of transfering the already developed seismic viewer program, originally built on top of wxWidgets, and though the portings are taking my time, I do think it’s worthwhile to migrate now, then to continue with the current library. One thing leaving me out of terms with wxWidgets was always of its limited 3D graphics extendability. Even though it supports openGL, the lack of external integrated graphic toolkit, left me fazed, not expecting myself to code everything including plotting libraries and all.