Results 1 to 3 of 3

Thread: QHeaderView saveState()

  1. #1
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QHeaderView saveState()

    Can't get this to work. Model and view have already been defined and view shows data - header looks fine.

    Qt Code:
    1. header = new QHeaderView(Qt::Horizontal);
    2. view->setHorizontalHeader(header);
    3.  
    4. ha = header->saveState();
    To copy to clipboard, switch view to plain text mode 

    Compiles fine, runs with no errors.
    Problem is the array is empty, but has size 426. No values in it.
    What am I doing wrong?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QHeaderView saveState()

    If it has a size of 426 then there a 426 bytes in the array, but they are probably no al printable. A serialised form from QSettings for a fairly wide table looks like (wrapping is mine):
    Qt Code:
    1. LogTable=@ByteArray(\0\0\0\xff\0\0\0
    2. \0\0\0\0\x1\0\0\0\0\0\0\0\x4\0\0\0\0%\0\0\0\0\0\0\0\x1\0\0\0\x2\0\0\0\x3\0\0\0\x4\0\0
    3. \0\x5\0\0\0\x6\0\0\0\a\0\0\0\b\0\0\0\t\0\0\0\n\0\0\0\v\0\0\0\f\0\0\0\r\0\0\0\xe\0\0\0\xf
    4. \0\0\0\x10\0\0\0\x11\0\0\0\x12\0\0\0\x13\0\0\0\x14\0\0\0\x15\0\0\0\x16\0\0\0\x17
    5. \0\0\0\x18\0\0\0\x19\0\0\0\x1a\0\0\0\x1b\0\0\0\x1c\0\0\0\x1d\0\0\0\x1e\0\0\0\x1f
    6. \0\0\0 \0\0\0!\0\0\0\"\0\0\0#\0\0\0$\0\0\0%\0\0\0\0\0\0\0\x1\0\0\0\x2\0\0\0\x3\0
    7. \0\0\x4\0\0\0\x5\0\0\0\x6\0\0\0\a\0\0\0\b\0\0\0\t\0\0\0\n\0\0\0\v\0\0\0\f\0\0\0\r\0\0\0
    8. \xe\0\0\0\xf\0\0\0\x10\0\0\0\x11\0\0\0\x12\0\0\0\x13\0\0\0\x14\0\0\0\x15\0\0\0\x16
    9. \0\0\0\x17\0\0\0\x18\0\0\0\x19\0\0\0\x1a\0\0\0\x1b\0\0\0\x1c\0\0\0\x1d\0\0\0\x1e\0\0\0
    10. \x1f\0\0\0 \0\0\0!\0\0\0\"\0\0\0#\0\0\0$\0\0\0%\xf\0\0\0\0\0\0\0\x4\0\0\0\x3\0\0\0
    11. \x64\0\0\0\x2\0\0\0\x64\0\0\0\x1\0\0\0\x64\0\0\0\0\0\0\0\x64\0\0\f\xe4\0\0\0%\x1\x1
    12. \0\0\0\0\0\0\0\0\0\0\0\0\0\0\x64\xff\xff\xff\xff\0\0\0\x84\0\0\0\0\0\0\0\x5\0\0\0\0\0
    13. \0\0\x1\0\0\0\0\0\0\0\0\0\0\0\x1\0\0\0\0\0\0\0\0\0\0\0\x1\0\0\0\0\0\0\0\0\0\0\0\x1
    14. \0\0\0\0\0\0\f\xe4\0\0\0!\0\0\0\0)
    To copy to clipboard, switch view to plain text mode 
    If you fed this byte array to a C printf() then you would see nothing because it starts with a NUL (\0) character. Same seems to apply to qDebug(). Restoring the table state using the stored data works OK. Try dumping it:
    Qt Code:
    1. qDebug() << ha.toHex()
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to ChrisW67 for this useful post:

    waynew (26th December 2009)

  4. #3
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QHeaderView saveState()

    Thanks Chris - working perfectly now. I also had to move the restoreState code from a separate function up to where I was opening the new database as the reference to the header was getting lost some way. But that's ok, it's a small bit of code and it works now.
    Happy holidays!

Similar Threads

  1. QHeaderView
    By waynew in forum Qt Programming
    Replies: 2
    Last Post: 25th December 2009, 20:42
  2. QHeaderView -- diagonal headers?
    By vycke in forum Qt Programming
    Replies: 7
    Last Post: 28th April 2008, 23:54
  3. Replies: 2
    Last Post: 14th August 2007, 15:16
  4. QHeaderView as a banner
    By mclark in forum Qt Programming
    Replies: 1
    Last Post: 21st March 2007, 19:28
  5. Renumbering Row Headers of QHeaderView
    By mclark in forum Newbie
    Replies: 4
    Last Post: 11th September 2006, 15:04

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.