PDA

View Full Version : Are there C/C++ commands which don't work with Qt?



Mariane
30th January 2006, 23:16
This is either a very silly mistake which is staring me in the face,
or something weird...


in maze.h:

class MazeField : public QWidget {

Q_OBJECT
public:
MazeField( QWidget *parent=0, const char *name=0 );

QSizePolicy sizePolicy() const;

(...)
int ** Log;
void MazeField::intialiseLog();
(...)
};


in maze.cpp:

int NUMBER_OF_COLUMNS = 4;
int NUMBER_OF_ROWS = 10;

(...)

// Used at initialisation
void MazeField::intialiseLog() {
Log = (int **) calloc ((NUMBER_OF_COLUMNS + 1), sizeof(int *));
for (int col = 0; col < NUMBER_OF_COLUMNS; col++) {
Log[col] = (int *) calloc ((NUMBER_OF_ROWS + 2), sizeof(int));
}
Log[0][0] = 3;
Log[0][5] = 5;
for (int row = 0; row < NUMBER_OF_ROWS; row++) {
for (int col = 1; col < NUMBER_OF_COLUMNS; col++) {
cout << Log[col][row];
}
cout << endl;
}
exit(0);
}

It outputs :

000
000
000
000
000
000
000
000
000
000

And I've been unable to make it output any number except zeros... :confused:

Mariane

jacek
30th January 2006, 23:26
for (int col = 1; col < NUMBER_OF_COLUMNS; col++) {
Try with "col = 0".

PS. Next time, please use [ c o d e ] tags.

fullmetalcoder
31st January 2006, 15:36
Talking about C++ aren't you??? So why do you use calloc instead of new ??? it produces hardly readable code and has no avantages in your case since you initialize all the items of your array!