Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Default values for binary data from QMainWindow::saveState
QtWS25 Last Chance

Default values for binary data from QMainWindow::saveState

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 1.5k Views
  • 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 Offline
    W Offline
    Wurgl
    wrote on last edited by
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      0
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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
        1
        • mrjjM mrjj

          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 Offline
          W Offline
          Wurgl
          wrote on last edited by
          #4

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

          mrjjM 1 Reply Last reply
          0
          • W Wurgl

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

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @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
            0
            • mrjjM mrjj

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

              W Offline
              W Offline
              Wurgl
              wrote on last edited by
              #6

              @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

              mrjjM 1 Reply Last reply
              0
              • W Wurgl

                @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

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by mrjj
                #7

                @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
                0
                • mrjjM 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 Offline
                  W Offline
                  Wurgl
                  wrote on last edited by
                  #8

                  @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
                  0
                  • mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

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

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved