[Qt-interest] ByteArray database problem
RZ
rz at univie.ac.at
Wed Aug 5 23:52:50 CEST 2009
Thx,
though in my case I had to do an additional wrapping:
insertQuery.bindValue(":val",
QString(horizontalHeader()->saveState().toHex()));
because storing the QByteArray directly in the varchar2 field gave
corrupted results (don't know if that's because Oracle, varchar2, ..)
Regards,
RZ
> 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
>
More information about the Qt-interest-old
mailing list