Weird results when passing a QByteArray* to a method
Hello,
I am having some very weird problems passing a QByteArray* to a method to retrieve BLOB data from a SQL DB. When I check the length of the QByteArray* in the method it is the size I expect, when I check it outside the method it is zero. Does anybody have any suggestions. This is probably something simple and I've just been working too long today:p
Code:
void class::callingMethod(int ID)
{
class2Object->getData(ID, data);
qDebug() << "Data length = " << data->length();
}
Code:
{
// ... do query
inData = dbData;
qDebug() << "dbData Length = " << dbData->length();
qDebug() << "inData Length = " << inData->length();
}
The output is:
Quote:
dbData Length = 2559219
inData Length = 2559219
Data Length = 0
Re: Weird results when passing a QByteArray* to a method
The output is correct as "data" still points to the original byte array. There is no point in using pointers here, anyway.
Code:
void cls::callingMethod(int id){
}
// ...
return q.value(0).toByteArray()'
}
Or optionally if you really want to reuse an external byte array:
Code:
void cls::callingMethod(int id){
class2Object->getData(id, data);
}
// ...
ba = q.value(0).toByteArray();
}
...or with a pointer...
Code:
void cls::callingMethod(int id){
class2Object->getData(id, &data);
}
// ...
*ba = q.value(0).toByteArray();
}