How can I represent a char from Qt as a string of bits in binary in Qml?

  • I have a char type that I need to represent as a byte (string of 8 bits) in Qml. How can that be achieved?

    Currently, I have this function QString statusBinary() { return QString::number((int)_status, 2); } as a public slot and exposed to Qml (I can call the function from Qml without any errors), but the result is always 0. _status is a char, btw. Even though I can see the value is changing. What am I doing wrong?

  • Lifetime Qt Champion


    What is the value of _status ?

  • I set status to a binary value like this: _status = 0b00010011, but the value is constantly changing by bitwise operations.

  • Do you emit a statusBinaryChanged(_status) when _status changes though? Else your QML won't know the C++-domain value has changed.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.