View Full Version : pass QByteArray as a pointer

6th December 2012, 11:32
How can I pass QByteArray as a pointer.
My function:
void removeStars(QByteArray *array){
And I am doing this:

QByteArray array;

I got this error:
QByteArray::operator QNoImplicitBoolCast() const’ is private

I tried as it would be char * but it didn’t work too. I mean I used this array like a pointer when I passed it.

6th December 2012, 11:41
Why do you want to pass a byte array as pointer?

By the way, the error you are getting is not related to the code you posted.

6th December 2012, 13:30
I would like to change 39 QByteArrays one by one.
I would like to remove some characters from them.
How can I do it anyway?

Added after 22 minutes:

You were right. The problem is not with argument passing.
I would like to remove ‘*’ from array.
This is the algorithm:

void StationsHandler::removeStars(QByteArray *encodedString){

int size = encodedString->size();
for (int i = 0; i < size; i++ ){
if (*(encodedString) == '*'){
for (QByteArray *temp = encodedString; j < size; j++){
*(temp) = *(temp+1);

*(encodedString+1) = '\0';

Added after 9 minutes:

Thank you I have found the problem. You were write the problem was out of this part of code.

6th December 2012, 21:15
I think you should read about QByteArray::replace() (many variants) and QByteArray::remove() and save yourself a bunch of effort and a whole lot of potential errors.

QByteArray toStrip("This contains an * asterisk, maybe more * than one");
qDebug() << toStrip.replace("*", "");
// Output: "This contains an asterisk, maybe more than one"