Results 1 to 3 of 3

Thread: SQLite connection and encoding

  1. #1
    Join Date
    Nov 2009
    Posts
    15

    Default SQLite connection and encoding

    Hello.

    I'm having some encoding problems when QT SQLite connection ( QSqlDatabase::addDatabase("QSQLITE") ) tries to read data from a SQLite archive.
    I assign a field value from the database into a QString variable:

    Qt Code:
    1. QString str001;
    2. str001 = record.value("title").toString();
    To copy to clipboard, switch view to plain text mode 

    I assume that the field contains a UTF-16 encoding (SQLite3 documentation) and I assume that QT4 processes information as UTF-16 unless I use specific functions. And I'm triyng to compile my program under Windows XP SP3 that uses UCS-2 / UTF-16 for heir standard Unicode encoding.
    But when field information displays on the screen I obtain the "?" code for non-standard chars like accentuated vowels or another specific symbols.
    I have tried to display the information in a label, a text box, a list box, a table, ... But always is the same. If QT display standard QStrings (not from SQLite), the output is encoding correctly.
    Is there any way of finding out what is getting lost in the conversion process? Something that warns about the incorrect codification (in the database, the driver, in my head, ...) or something like that.


    Thanks.
    Last edited by mhbeyle; 2nd December 2009 at 17:07.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: SQLite connection and encoding

    Hmm... as far as I know SQLite uses UTF-8 by default.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Nov 2009
    Posts
    15

    Default Re: SQLite connection and encoding

    Quote Originally Posted by wysota View Post
    Hmm... as far as I know SQLite uses UTF-8 by default.
    Finally I resolved the issue...

    SQLite3 adds support for both UTF-8 and UTF-16 text and SQLite driver in QT4 uses UTF-16 functions when opens and manipulates the database (qsql_sqlite.cpp -> sqlite3_open16).
    The problem was that I was creating the database with SQLite Administrator (http://sqliteadmin.orbmu2k.de/) and this tool seemingly doesn't support UTF-16 or, at least, it creates the database in UTF-8 by default. I noticed about this behavior when I opened the database with a hex-editor. Chars were written with UTF-8 encoding and one byte.
    And the problem grows more when QT believes that data is UTF-16 encoding because SQLite driver processes data in this manner. The conversion functions do not work as it stems and QT4 writes and reads the data with two bytes but in UTF-8. A real foul-up

    Of course and finally, I created the db in UTF-16

    Thank you very much for your attention.

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.