Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Default values for binary data from QMainWindow::saveState

    General and Desktop
    3
    9
    1049
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • W
      Wurgl last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        Are you thinking about the sizes of your widgets or their setup like which QDockWidget goes where ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • mrjj
          mrjj Lifetime Qt Champion last edited by

          Hi
          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.

          W 1 Reply Last reply Reply Quote 1
          • W
            Wurgl @mrjj last edited by

            @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.

            mrjj 1 Reply Last reply Reply Quote 0
            • mrjj
              mrjj Lifetime Qt Champion @Wurgl last edited by

              @Wurgl
              Qt3 ? wow :)
              Ok i understand.
              Somewhere in Qt code there is something that can read such string but not sure its public.

              W 1 Reply Last reply Reply Quote 0
              • W
                Wurgl @mrjj last edited by

                @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

                mrjj 1 Reply Last reply Reply Quote 0
                • mrjj
                  mrjj Lifetime Qt Champion @Wurgl last edited by mrjj

                  @Wurgl
                  Hehe awww :)
                  That is hard core maintenance :)

                  How are you saving the layout ?
                  Since we have
                  restoreGeometry(settings.value("myWidget/geometry").toByteArray());
                  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.

                  W 1 Reply Last reply Reply Quote 0
                  • W
                    Wurgl @mrjj last edited by

                    @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
                    [Win1,0,1,-1,302,1][Win2,0,0,-1,302,1]\n

                    Now it seems to have the same information, but in binary format.

                    1 Reply Last reply Reply Quote 0
                    • mrjj
                      mrjj Lifetime Qt Champion last edited by

                      Hi
                      For the data sample.
                      Do you provide the layout= name/key or is that from Qt ?

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post