Default values for binary data from QMainWindow::saveState
I have here some window with a few QDockWindow subwindows. And I have a nice layout. Sadly, I see no way to construct this layout by my program. Now I can store that layout with QSettings and when the program starts again, it will use that layout.
But in a fresh installation I have no stored settings, so I need some default.
In the ini-file format, that stored layout looks like:
layout="@ByteArray(\0\0\0\xff\0\0\0\0\xfd\0... I counted 420 bytes of binary data
Is there any simple way to use exactly that string in my program and to construct a QByteArray from it? I already looked at the QSettings and the QVariant class, but did not find anything … any ideas?
Are you thinking about the sizes of your widgets or their setup like which QDockWidget goes where ?
If you use ini files, could you not just make a good default .ini file, put it in the .exe via resource file
and in case that app cant find a .ini file, it will copy the one from res file and
load it. Would also allow for a "Reset layout/settings" options.
@mrjj The Application already has some files holding various defaults. Until now I used Qt3 and Qt3 had fine user-readable data without any binary stuff in it (see QTextStream & operator<<(...)). So the default values lived in those already existing files. Now with porting to Qt4 (and somewhen later to Qt5) the data seems to be binary and I want this data somehow user-readable without writing too much new code. Therefore I was thinking about something like the content of the ini-files, which is @ByteArray(...lot of backslash stuff…). Resource file is an idea, but this would split the defaults to just another place which I would not prefer. If there is some existing method to convert a string like you see in the inifile to a real ByteArray, I would prefer this.
Qt3 ? wow :)
Ok i understand.
Somewhere in Qt code there is something that can read such string but not sure its public.
@mrjj Some parts of this code-monster has code written in 1987 (at least a few comments show that year) … so Qt3 is the really modern part ;-D
Hehe awww :)
That is hard core maintenance :)
How are you saving the layout ?
Since we have
there must be something similar for the "layout" type.
The QWidget::saveGeometry() seems to save store screen number, geometry and window state.
But if there are 400 bytes of data, more must be saved.
@mrjj save/restoreState and save/restoreGeometry Geometry is not soooooo long, the state (holding the layout, the position of the dockable windows) is the long one. I think, there are 5 such dockable widgets. And it seems that some name in UCS-2 encoding (or similar maybe internal representation of a QString?) is part of each of those dockWindows.
In Qt3 the String looked like:
Standard Toolbar,foo Toolbar,\n[Standard Toolbar,0,1,-1,-1,1][foo Toolbar,0,0,-1,-1,1]\nWin1,Win2,\n
Now it seems to have the same information, but in binary format.
For the data sample.
Do you provide the layout= name/key or is that from Qt ?