I want to convert a number (f. e. 1000) into a very specific ByteArray. At least I guess it's a bytearray, since it says it's one.
@ByteArray(\x1\xd9\xd0\xcb\0\x1\0\0\0\0\0\xc2\0\0\0X\0\0\x3)\0\0\x2"\0\0\0\xca\0\0\0w\0\0\x3!\0\0\x2\x1a\0\0\0\0\0\0)
(This ByteArray is used in "vlc-qt-interface.ini" from vlc)
I do not know what format this byte array is using and I couldn't decode it yet myself. Do you have an idea how to decode it and then encode a number into this format? This format probably contains at least two numbers, likely four (I want to convert to same amount of numbers as are used).
This is a bit trickier than it looks. For the shortest answer possible, see this bug report (open) which basically says the restoreGeometry routine is too complicated. Some of the critique in the bug report is what is going to make this hard for you to do what you are probably intending.
The longer answer is that it is a QByteArray that gets written out as a result of saveGeometry(). The same QByteArray is fed back into it at the start to set up the geometry. The actual string you posted is an ini escaped string: https://doc.qt.io/qt-5/qsettings.html
QSettings will accept Latin-1 encoded INI files, but generate pure ASCII files, where non-ASCII values are encoded using standard INI escape sequences.
The structure of the geometry isn't documented, near as I can tell. However, a review of qwidget.cpp in the restoreGeometry() function reveals the following:
It starts with a magic 32-bit number 0x1D9D0CB
(\x1\xd9\xd0\xcb when encoded). The next 16 bits are the 'major version' and the 16 after that the 'minor version'. Then, in order:
const quint32 magicNumber = 0x1D9D0CB
quint16 majorVersion;
quint16 minorVersion;
QRect restoredFrameGeometry;
QRect restoredGeometry;
QRect restoredNormalGeometry;
qint32 restoredScreenNumber;
quint8 maximized;
quint8 fullScreen;
qint32 restoredScreenWidth = 0;
Each QRect appears to be in the order of left, top, right, and then bottom:
QDataStream &operator<<(QDataStream &s, const QRect &r)
{
if (s.version() == 1)
s << (qint16)r.left() << (qint16)r.top()
<< (qint16)r.right() << (qint16)r.bottom();
else
s << (qint32)r.left() << (qint32)r.top()
<< (qint32)r.right() << (qint32)r.bottom();
return s;
}
It is slightly unclear if version 1 or otherwise is being used for the QRect, but based on the rough size of the encoded string, I am pretty sure it would be 16-bits.
I am not sure which of the Geometries you are actually trying to influence. Instead of trying to encode and change these, I would recommend coming up with a simple QT program which you can instead open and use yourself the QSettings to save off the desired sizes and load in the ini file for later.
Fore completeness of the answer: when saveGeometry is called, it returns a QByteArray which is then set/saved in QSettings.
This code snippet from 'extended.cpp' (in VLC) appears to restore it on load, defaulting to a size of 400, 200 if the setting can't be found:
if( !restoreGeometry( getSettings()->value("EPanel/geometry").toByteArray() ) )
{
resize( QSize( 400, 280 ) );
MainInterface *p_mi = p_intf->p_mi;
if( p_mi && p_mi->x() > 50 )
move( ( p_mi->x() - frameGeometry().width() - 10 ), p_mi->y() );
else
move ( 450 , 0 );
}