I'm trying to convert an int to QByteArray
. I'm using this method QByteArray::number(m_vman);
is it correct?
I'm trying to use the number()
for getting an int to QByteArray
.
I'm trying the following code but the bytearray is zero
QByteArray vmanByteArray, vheaterByteArray;
QDataStream streamVMan(&vmanByteArray, QIODevice::WriteOnly);
QDataStream streamVHeater(&vheaterByteArray, QIODevice::WriteOnly);
streamVMan << m_vman;
streamVHeater << m_vheater;
QByteArray arr = m_htman ? vmanByteArray : vheaterByteArray;
Here's for an int: int i = 42; QString s = QLocale(). toString(i);
QByteArray can be used to store both raw bytes (including '\0's) and traditional 8-bit '\0'-terminated strings. Using QByteArray is much more convenient than using const char * .
An int value can be converted into bytes by using the method int. to_bytes(). The method is invoked on an int value, is not supported by Python 2 (requires minimum Python3) for execution.
you can simply do like this.
int myInt = 123;
QByteArray q_b;
q_b.setNum(myInt);
Related to the actual question title, the following static function should definitely work:
QByteArray::number
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With