PDA

View Full Version : Accessing QList Objects



magikalpnoi
20th September 2006, 17:47
I could use some help....

I am trying to access a 2 dimensional array of QList objects. What it is a QVariantList (which is actually a typedef in QVariant as a QList<QVariant>) passed into another QList<QVariantList> to form a 2 dimensional array. The original QVariantList has a blank character array of 100 chars so the QList is a 2 dimensional array of chars. Or at least it is supposed to be (I can't get passed the error so I haven't been able to check).

Why would I ever want to do something so complicated? Well if you really want to know, I am trying to use a stored procedure in an Oracle database that calls for a 2d array of chars as one of the parameters. I am composing an update of existing technology to change it into the newer QT environment. I'm essentially trying to convert ProC (if you have ever heard of that language) to C++.

So now on to the question. I have passed the 2d QList into the stored procedure and now I am trying to get into the QList to retrieve the data. The code I tried below doesn't seem to work. HELP!!! In advance, I thank you. :)

--Normal C++ 2D Array--

char sIntAlignZone [100][2];

--QList Version--

QVariantList charArray;
for(int i = 0; i < 100; i++)

charArray << QVariant(QVariant::ByteArray);
QList<QVariantList> sIntAlignZone;
for(int j = 0; j < 2; j++)

sIntAlignZone << charArray;

--After Stored Procedure--

dataP->alignZone = sIntAlignZone[i][0];

--Compile Error--

FitcheckDB.cpp(691) : error C2440: '=' : cannot convert from 'QVariant' to 'char'

wysota
20th September 2006, 17:58
Do you really need QVariant here? If you just want a 2D array of chars constant size, why not use char[][]? Or QVarLengthArray< QVarLengthArray< QChar > > if you insist on using Qt types.

Trasmeister
20th September 2006, 18:07
Do you really need QVariant here? If you just want a 2D array of chars constant size, why not use char[][]? Or QVarLengthArray< QVarLengthArray< QChar > > if you insist on using Qt types.

I would agree with the above; However, the reason for the compile problem is that it can't automatically convert a QVariant (passed back from sIntAlignZone[x][y]) to a char.



To do the conversion, you'd have to do an explicit conversion along the lines of this:



QChar theQChar = sIntAlignZone[x][y].toChar();
char myChar = theQChar.unicode();

wysota
20th September 2006, 18:16
But the question remains -- what do you need QVariant for?

magikalpnoi
20th September 2006, 18:43
The reason for a QVariant is because in order to use a stored procedure via QSqlQuery and binding values you need to pass in a QVariant of some sort.

I'm going to try the QChar way but keep replying if it doesn't work. Thanks everyone.

magikalpnoi
20th September 2006, 19:52
I attempted this but I believe the way that a QList << call is structured so that the QVariantLists are on top of each other and not side by side...

--I'm attempting to make this--
char sActWBS [100][2];

//First of all I make a QVariantList filled with 100 chars
QVariantList charArray;
for(int i = 0; i < 100; i++)

charArray << QVariant(QVariant::Char);

//Then I put 10 of the charArray lists into another QList
QList<QVariantList> sActWBS;
for(int j = 0; j < 10; j++)

sActWBS << charArray;


Do you think this will work like a 2d array?

If so, how do I parse the array once I am finished, starting with the first column then the second and so on.

If not, I know that I could write a function to manipulate the data like a 2d array if my assumption is correct and the QVariantLists are on top of each other but this doesn't satisfy the stored procedure parameter that I need (a 2d char array).

I didn't realize that this was going to be so complicated. If anyone has a better idea of how to make a 2d char array using QVariant I am all ears. Before submitting it, make sure that a BindValue function parameter in QSqlQuery will support the idea. It needs a QVariant object to be passed into it to work properly.

Thank you again.

magikalpnoi
21st September 2006, 18:13
Can anyone think of another way to implement a 2d char array into a 2d array of QVariants for a BindValue function parameter in QSqlQuery to accept???

wysota
21st September 2006, 21:43
Maybe you could use QVector instead of QList? And if not, why not provide your own serialisation of data and go directly for QByteArray which can be stored in QVariant?