PDA

View Full Version : How to resolve qbyteA[5] = qbyteB?



hiuao
11th January 2008, 04:38
Hi,every one!Can you tell me how to resolve the following problem?

QByteArray qbyteA,qbyteB;
qbyteA.resize(9);
........
qbyteA[5] = qbyteB;//error: QByteArray:: operator QNoImplicitBoolCast() const' is private
I don't know why,please anyone if you know tell me,thank you very much!

aamer4yu
11th January 2008, 05:55
What are you trying to achieve ?
qByteA[5] = qByteB ; Here you are trying to assign the byte array qByteB to sixth character of qByteA (qByteA[5]) . How can this be possible ??
You can assign character to character. If qByteA was an array of pointers to QByteArray, then that statement would have worked.

Hence its giving error that it cannot find any suitable conversion for the statement.

hiuao
11th January 2008, 08:24
Thank you for your kind help,but I have already try for many ways,such as

QByteArray byteA[9],byteB; or QByteArray *byteA,byteB;
byteA[0] = 0x23;//error: invalid conversion from `int' to `const char*'
I want to give
byteA[i] = 0xxx,byteA[j] = byteB,how I can do? Please!

aamer4yu
11th January 2008, 10:42
You can assign hex values to QByteArray,,, like qByteA[5] = 0xA2 - Hex format.
or u can use QByteArray::fromHex.

If you are trying to assign some part of qByteB to qByteA then trim qByteB first and use the assignement operator.

hiuao
11th January 2008, 11:24
Why?But there no member QByteArray::fromHex.

jacek
11th January 2008, 12:52
QByteArray byteA[9],byteB; or QByteArray *byteA,byteB;
byteA[0] = 0x23;//error: invalid conversion from `int' to `const char*'
Here byteA is an array of QByteArrays, so byteA[0] is QByteArray.


I want to give byteA[i] = 0xxx,byteA[j] = byteB,how I can do?
Make sure the types match:

QByteArray byteA, byteB;
...
byteA[0] = 0x11;
byteA[1] = byteB[2];

aamer4yu
11th January 2008, 13:31
Why?But there no member QByteArray::fromHex.
Why ? did u click on the link ? Its a static member function.

hiuao
12th January 2008, 04:08
Sorry to replay so late.I think your version maybe QT4.3,but mine is QT4.2.2,so there is no fromHex in my version.I want to do as the following,please tell me if I am right,Thank you very much!


QByteArray bytA[3],bytB;
bytA[0] = "0x34";
bytA[1] = bytB;
bytA[2] = QByteArray( ( 2*(bytA[0].toLong())& 0x000000ff )<<8 );

I want to know if the function use "QByteArray::toLong(),& ,<<" is right.

hiuao
12th January 2008, 04:38
Here byteA is an array of QByteArrays, so byteA[0] is QByteArray.

Make sure the types match:

QByteArray byteA, byteB;
...
byteA[0] = 0x11;
byteA[1] = byteB[2];

I don't think its proper,excuse me to say so.If byteB only have one byte,how can it do?

jacek
12th January 2008, 13:33
If byteB only have one byte,how can it do?
Even if it contains a single byte, still its type is QByteArray. You have to extract that single byte in order to make the assignment:
byteA[2] = byteB[0];