Blog Image

Notes

Memory management C/C++

C++ Posted on Thu, August 30, 2007 08:40:25

In C++ we have the operator new and operator delete. These are intended to replace malloc() and free() in the C standard library.

Allocating a array of 100 integers is done in C as follows:

int* is;
is = (int*)malloc(sizeof(int) * 100);

free((void*)is);

With new/delete in C++, it can be rewritten as:

int* is;
is = new int[100];

delete is;



External library dependency

Qt Posted on Thu, August 30, 2007 08:19:49

When you change an external library, your Qt project is not recompiled. By default, qmake does not include external libraries in the dependencies for the final executable, because they are not part of the project itself. This can easily be solved by adding a forced dependency in the .pro file:

POST_TARGETDEPS += /libpath/libCAD.a



QVTKWidget BadWindow

Qt Posted on Thu, August 30, 2007 08:09:41

Using VTK (QVTKWidget) in combination with Qt 4.2.0 or Qt 4.2.1, which is included in the SuSe 10.2 distribution, can cause the following errors:

X Error: BadWindow (invalid Window parameter) 3
Major opcode: 3 (X_GetWindowAttributes)
Resource id: 0x0
X Error: BadValue (integer parameter out of range for operation) 2
Major opcode: 1 (X_CreateWindow)
Resource id: 0x0
X Error: BadWindow (invalid Window parameter) 3
Major opcode: 20 (X_GetProperty)
Resource id: 0x0
X Error: BadWindow (invalid Window parameter) 3
Major opcode: 3 (X_GetWindowAttributes)
Resource id: 0x3c00002
Segmentation fault

This is a bug introduced in Qt 4.2.0 where they delete all descending underlying windows when reparenting a widget. This is fixed in Qt 4.2.2. More information here.