Search code examples
c++qtqfileqbytearray

Send Hex command with QByteArray and QFile


so i need to send thru UART a command which is in Hex. I tried to assign directly to QByteArray but without success

QByteArray test = 0x21, 0x30, 0xFF... //the result is that test is empty.

I did try to assign thru a QString

QString t = 0x21, 0x30, 0xFF...

file->write(t.toLatin1()) //also without success. 

Does anyone know how to solve this problem? Thanks for the attention.


Solution

  • QByteArray test = QByteArrayLiteral("\xDE\xAD\xBE\xEF");
    

    That should work.

    Also, you might want want to work on them C++ skills a bit more, because what you attempted is definitely not how the language works. A list initializer maybe... but comma separated values?