The output is correct as "data" still points to the original byte array. There is no point in using pointers here, anyway.
void cls::callingMethod(int id){
}
// ...
return q.value(0).toByteArray()'
}
void cls::callingMethod(int id){
QByteArray data = class2Object->getData(id);
}
QByteArray cls2::getData(int id){
QSqlQuery q(...);
// ...
return q.value(0).toByteArray()'
}
To copy to clipboard, switch view to plain text mode
Or optionally if you really want to reuse an external byte array:
void cls::callingMethod(int id){
class2Object->getData(id, data);
}
// ...
ba = q.value(0).toByteArray();
}
void cls::callingMethod(int id){
QByteArray data;
class2Object->getData(id, data);
}
void cls2::getData(int id, QByteArray &ba){
QSqlQuery q(...);
// ...
ba = q.value(0).toByteArray();
}
To copy to clipboard, switch view to plain text mode
...or with a pointer...
void cls::callingMethod(int id){
class2Object->getData(id, &data);
}
// ...
*ba = q.value(0).toByteArray();
}
void cls::callingMethod(int id){
QByteArray data;
class2Object->getData(id, &data);
}
void cls2::getData(int id, QByteArray *ba){
QSqlQuery q(...);
// ...
*ba = q.value(0).toByteArray();
}
To copy to clipboard, switch view to plain text mode
Bookmarks