QList is still empty
-
Hi! I have Qlist<double> where I wanna add some items and after I want read this data from it. I have loop where I'm adding some data using function append, but my QList is still empty! Here's my code:
@
int x, y;
//...
if (gData.columnsX.count() == 1) {
QList<double> udajeX;
for (x = gData.lineRange.from, y=1; x <= gData.lineRange.to; x++, y++) {
if (provider->getColumnType(gData.columnsX.at(0).name) != "real") {
udajeX.append(y);
udajeX.insert(y-1, (double)y);
//qDebug() << (double)y;
}
else {
udajeX.append(provider->model->record(x-1).value(gData.columnsX.at(0).name).toDouble());
qDebug() << provider->model->record(x-1).value(gData.columnsX.at(0).name).toDouble();
}
}
qSort(udajeX);
QPointF pFrom, pTo;
for (x = gData.lineRange.from; x <= gData.lineRange.to; x++) {
for (y = 1; y < gData.columnsY.count(); y++) {
pFrom.setX(udajeX.at(x-1) * gData.columnsX.at(0).max / 400);
pFrom.setY(provider->model->record(x-1).value(gData.columnsY.at(y-1).name).toDouble() * gData.columnsY.at(0).max / 300);
pTo.setX(udajeX.at(x) * gData.columnsX.at(0).max / 400);
pTo.setY(provider->model->record(x).value(gData.columnsY.at(y-1).name).toDouble() * gData.columnsY.at(0).max / 300);
qDebug() << udajeX.at(x); //nothing!
//qDebug() << "X:" << udajeX.at(x-1) * gData.columnsX.at(0).max / 400 << "Y:" << provider->model->record(x-1).value(gData.columnsY.at(y-1).name).toDouble() * gData.columnsY.at(0).max / 300;
//qDebug() << "X:" << udajeX.at(x) * gData.columnsX.at(0).max / 400 << "Y:" << provider->model->record(x).value(gData.columnsY.at(y-1).name).toDouble() * gData.columnsY.at(0).max / 300;
//qDebug() << "---------------------------------------";
//qDebug() << "From " << x-1 << " to " << x;
painter->drawLine(pFrom, pTo);
}
}
//qDebug() << provider->getColumnType(gData.columnsX.at(0).name);
}
@It can be stupid problem but I'm tired and i can't found any mistake :) Thanks!
[EDIT: reformatted code, Volker]
-
You should check if there is something in the udajeX around your qSort().
@
int x, y;
...
if (gData.columnsX.count() == 1) {
QList<double> udajeX;
for (x = gData.lineRange.from, y=1; x <= gData.lineRange.to; x++, y++) {
if (provider->getColumnType(gData.columnsX.at(0).name) != "real") {
udajeX.append(y);
udajeX.insert(y-1, (double)y);
//qDebug() << (double)y;
}
else {
udajeX.append(provider->model->record(x-1).value(gData.columnsX.at(0).name).toDouble());
qDebug() << provider->model->record(x-1).value(gData.columnsX.at(0).name).toDouble();
}
}
qDebug() << udajeX.size(); // <<<<<<<<<<<<<<<<<<<<<<<
qSort(udajeX);
qDebug() << udajeX.size(); // <<<<<<<<<<<<<<<<<<<<<<<<
QPointF pFrom, pTo;
for (x = gData.lineRange.from; x <= gData.lineRange.to; x++) {
qDebug() << "gData.columnsY.count() " << gData.columnsY.count(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
for (y = 1; y < gData.columnsY.count(); y++) {
pFrom.setX(udajeX.at(x-1) * gData.columnsX.at(0).max / 400);
pFrom.setY(provider->model->record(x-1).value(gData.columnsY.at(y-1).name).toDouble() * gData.columnsY.at(0).max / 300);
pTo.setX(udajeX.at(x) * gData.columnsX.at(0).max / 400);
pTo.setY(provider->model->record(x).value(gData.columnsY.at(y-1).name).toDouble() * gData.columnsY.at(0).max / 300);
qDebug() << udajeX.at(x); //nothing!
//qDebug() << "X:" << udajeX.at(x-1) * gData.columnsX.at(0).max / 400 << "Y:" << provider->model->record(x-1).value(gData.columnsY.at(y-1).name).toDouble() * gData.columnsY.at(0).max / 300;
//qDebug() << "X:" << udajeX.at(x) * gData.columnsX.at(0).max / 400 << "Y:" << provider->model->record(x).value(gData.columnsY.at(y-1).name).toDouble() * gData.columnsY.at(0).max / 300;
//qDebug() << "---------------------------------------";
//qDebug() << "From " << x-1 << " to " << x;
painter->drawLine(pFrom, pTo);
}
}
//qDebug() << provider->getColumnType(gData.columnsX.at(0).name);
}
}
@
This is brain to keyboard source, but see, if it gives something meaningful. -
No change in size... I've tried this before
-
Does your program do the loop?
Furthermore, I am not sure since you are putting an int to QList<double> . I think it should not be a problem, but change it to
@
udajeX.append( double ( y ));
udajeX.insert(y-1, (double)y);
@
In addition that looks a little strange from the logic, but I assume that is because of your efforts to find the problem. -
I'm sorry for chaotic code but I'm looking for mistake a long time and some parts and lines of code are strange. I tried convert y from int to double before, but without any effect. And I have mistake in my previous post. In code is line with insert commented.
@udajeX.append(double (y));
//udajeX.insert(y-1,(double)y);
@ -
Did you use the debugger and checked that the program loops there ?
If it does not put anything in there, no wonder .... -
Is your first loop actually executed?
At the end of each loop iteration, check if something was added to the list.
Add@
qDebug() << udajeX;
@to see what's in the list.
PS:
Please remove leading whitespace from code snippets before posting, otherwise it makes lines wrap and reading hard. You're likely to disattract possibles helpers :-)