[Qt-interest] ByteArray database problem
Constantin Makshin
dinosaur-rus at users.sourceforge.net
Wed Aug 5 16:49:08 CEST 2009
Use QByteArray::toHex() and QByteArray::fromHex() functions when saving
and retrieving the value, respectively:
insertQuery.bindValue(":val", horizontalHeader()->saveState().toHex());
horizontalHeader()->restoreState(QByteArray::fromHex(query.value(0).toByteArray()));
You can find a working code in the attached archive (it uses SQLite
database for testing purposes, but that shouldn't be a problem).
On Wed, 05 Aug 2009 11:09:29 +0400, RZ <rz at univie.ac.at> wrote:
> Hello all,
>
> I got the following code for some of my QTableViews:
>
> in c'tor:
> QSettings settings("Zweieck", "PEPer");
> horizontalHeader()->restoreState(settings.value("test").toByteArray());
>
> and on closing:
> QSettings settings("Zweieck", "PEPer");
> settings.setValue("test", horizontalHeader()->saveState());
>
> which does what it should. Now I'm trying to save the data not via
> QSettings but to a database (Oracle in that case).
>
> Doing
> insertQuery.bindValue(":val", horizontalHeader()->saveState());
>
> gives me a string in the database (something like
> 00000FF000000000000000100000001000000000100000000....) - the field in
> the database is defined as varchar (if that should matter).
>
> When reading that again
> horizontalHeader()->restoreState(query.value(0).toByteArray());
> it stays without effect.
>
>
> Any ideas? How to correctly store a QByteArray in a database? (I fear
> that converting to and from string corrupts something).
>
> Any help appreciated,
>
> RZ
--
Constantin "Dinosaur" Makshin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: QtSettingsTest.tar.bz2
Type: application/bzip2
Size: 1339 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090805/be464488/attachment.bin
More information about the Qt-interest-old
mailing list