How to resolve qbyteA[5] = qbyteB?
Hi,every one!Can you tell me how to resolve the following problem?
Code:
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!
Re: How to resolve qbyteA[5] = qbyteB?
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.
Re: How to resolve qbyteA[5] = qbyteB?
Thank you for your kind help,but I have already try for many ways,such as
Code:
byteA[0] = 0x23;//error: invalid conversion from `int' to `const char*'
I want to give
Code:
byteA[i] = 0xxx,byteA[j] = byteB
,how I can do? Please!
Re: How to resolve qbyteA[5] = qbyteB?
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.
Re: How to resolve qbyteA[5] = qbyteB?
Why?But there no member QByteArray::fromHex.
Re: How to resolve qbyteA[5] = qbyteB?
Quote:
Originally Posted by
hiuao
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.
Quote:
Originally Posted by
hiuao
I want to give byteA[i] = 0xxx,byteA[j] = byteB,how I can do?
Make sure the types match:
Code:
...
byteA[0] = 0x11;
byteA[1] = byteB[2];
Re: How to resolve qbyteA[5] = qbyteB?
Quote:
Why?But there no member QByteArray::fromHex.
Why ? did u click on the link ? Its a static member function.
Re: How to resolve qbyteA[5] = qbyteB?
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!
Code:
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.
Re: How to resolve qbyteA[5] = qbyteB?
Quote:
Originally Posted by
jacek
Here byteA is an array of QByteArrays, so byteA[0] is QByteArray.
Make sure the types match:
Code:
...
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?
Re: How to resolve qbyteA[5] = qbyteB?
Quote:
Originally Posted by
hiuao
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:
Code:
byteA[2] = byteB[0];