PDA

View Full Version : QHeaderView saveState()



waynew
25th December 2009, 22:02
Can't get this to work. Model and view have already been defined and view shows data - header looks fine.



header = new QHeaderView(Qt::Horizontal);
view->setHorizontalHeader(header);

QByteArray ha;
ha = header->saveState();


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?

ChrisW67
26th December 2009, 04:13
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):
LogTable=@ByteArray(\0\0\0\xff\0\0\0
\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
\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
\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
\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
\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
\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
\xe\0\0\0\xf\0\0\0\x10\0\0\0\x11\0\0\0\x12\0\0\0\x 13\0\0\0\x14\0\0\0\x15\0\0\0\x16
\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
\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
\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
\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
\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
\0\0\0\0\0\0\f\xe4\0\0\0!\0\0\0\0) 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:


qDebug() << ha.toHex()

waynew
26th December 2009, 15:46
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!