Qt-interest Archive, March 2002
QString array
Message 1 in thread
Hello
I have very strange problem. I can't create 2-dimmensional QString
array. Programm compiles without errors but output is incorrect.
Element[whatever][0] == Element[whatever][1], always. I have compiled
this on RH7.2 with Ximian gnome and gcc 2.96. The came code works fine
with char* or QString* :-/
Sample code:
---[ cut ]---
#include <stdio.h>
#include <qstring.h>
int main(int argc, char *argv[])
{
static const char* chr[3][2] = {
{"one","two"},
{"three","four"},
{"five","six"},
};
static const QString qs1[3][2] = {
{QString("one"), QString("two")},
{QString("three"), QString("four")},
{QString("five"), QString("six")},
};
static const QString* qs2[3][2] = {
{new QString("one"), new QString("two")},
{new QString("three"), new QString("four")},
{new QString("five"), new QString("six")},
};
for (int i = 0; i < 3; i++) {
for (int j=0; j<2; j++) {
printf("chr[%d][%d] = %s\t", i, j, chr[i][j]);
printf("qs1[%d][%d] = %s\t", i, j, qs1[i][j].latin1());
printf("qs2[%d][%d] = %s\n", i, j, qs2[i][j]->latin1());
}
}
return 0;
}
---[ cut ]---
Here is my output (see middle row!):
chr[0][0] = one qs1[0][0] = one qs2[0][0] = one
chr[0][1] = two qs1[0][1] = one qs2[0][1] = two
chr[1][0] = three qs1[1][0] = three qs2[1][0] = three
chr[1][1] = four qs1[1][1] = three qs2[1][1] = four
chr[2][0] = five qs1[2][0] = five qs2[2][0] = five
chr[2][1] = six qs1[2][1] = five qs2[2][1] = six
Any ideas ?
--
[ signature omitted ]