converting qbyte array to string
-
@Anna_64 Can you please explain your problem in an understandable way?
What are x[j] and y[j]?
Did you check https://doc.qt.io/qt-5/qbytearray.html#fromBase64 ?
Did you check https://doc.qt.io/qt-5/qstring.html#fromLatin1-1 ? -
@jsulm x[i] and y[j] are the array which is in base 64
Now i have to convert that into a string and i have to send that into a device for updating x[i] and y[j] contains data that i need to be updated into device so now i have to do conversion to string and finally send data for updation in the below format
<size>2048</size>
<Data>x[j]</Data>
<offset>i.1024</offset>
<Signature>y[j]<Signature>
how u understand my question and this s the final stage of the project that is updating data into a device -
@Anna_64 I'm still not sure I understand you correctly as neither x[j] not y[j] are Base64 strings.
Check the links I provided abote to see how de decode Base64 into a QByteArray and then to a string.
Also, if you want to send it to a device then you don't need to convert it to a string just use the QByteArray you get from fromBase64() method. -
-
@jsulm QString s[64];
for(int j=0;j<64;j++){
s[j] ="<UpdateFirmware><Size>2048</Size><Data>"+QByteArray::fromBase64(x[j])+"</Data><Offset>008192</Offset>"+QByteArray::fromBase64(y[j])+"</UpdateFirmware>";
i have converted my q byte array of base 64 and s[j] should be sent into my device but its showing error -
@Anna_64 said in converting qbyte array to string:
showing error
if you get an error you should post it here...
-
-
@Anna_64 {
QByteArray uq;
uq.resize(7);
uq[0] = 0xAA;
uq[1] = 0x55;
uq[2] = 0x04;
uq[3] = 0x00;
uq[4] = 0x00;
uq[5] = 0xC0;
uq[6] = 0xBB;
serial->write(uq);
after this write command i have to close serial port and wait for 5 sec and open serial port and send data so after
serial->write(uq);
serial->close();
QThread::sleep(5);but it gives error like device not opened -
@jsulm QByteArray uq;
uq.resize(7);
uq[0] = 0xAA;
uq[1] = 0x55;
uq[2] = 0x04;
uq[3] = 0x00;
uq[4] = 0x00;
uq[5] = 0xC0;
uq[6] = 0xBB;
serial->write(uq);
after this write command i have to close serial port and wait for 5 sec and open serial port and send data so after
serial->write(uq);
serial->close();
QThread::sleep(5);but it gives error like device not opened -
@Anna_64 You should first wait until data was written before calling close(). See https://doc.qt.io/qt-5/qserialport.html#waitForBytesWritten
-
-
@jsulm QString s[64];
QString test ="";
QByteArray testfinal;
testfinal.resize(65000);
for(int j=0;j<64;j++)
{
QString offsetAddress=QString::number(j*1024).rightJustified(6, '0');
s[j] = "<UpdateFirmware><Size>2048</Size><Data>"+x[j]+"</Data><Offset>"+offsetAddress+"</Offset><Signature>"+y[j]+"</Signature></UpdateFirmware>";
//s[j] ="<UpdateFirmware><Size>2048</Size><Data>"+x[j]+"</Data><Offset>008192</Offset><Signature>"+y[j]+"</Signature></UpdateFirmware>";
if(j>=8){
testfinal+=s[j];
serial->write(testfinal);
}
i am trying to send this string message to my device and do updation but only 15% updation s happening theres no error as well but with testing i found complete updation s not happening
can u plz figure it which part of data not working i guess it s the offset adress part