Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Save a QString to sqlite and fetch it back?
Forum Updated to NodeBB v4.3 + New Features

Save a QString to sqlite and fetch it back?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 2.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    billconan
    wrote on last edited by
    #1

    Hello guys,

    I am writing an rss reader. I need a standalone database for storage. I chose sqlite, but I have problem saving QStrings to my database.

    here is how I save a QString to my sqlite database:

    @
    QByteArray qba;
    qba.append(sub.getTitle().toUtf8());

        bool bindresult=sqlite3_bind_text(insertASubscriptionStatement,2,qba.constData(), qba.count(), 0);
    

    @

    And this is how i get it back:

    @
    QString title=QString().fromUtf8((char*)sqlite3_column_text(fetchSubscriptionListStatement, 1));
    @

    this works well if the QString has only english characters, but messes up if it has Chinese characters. All the Chinese characters become ?? after reading back.

    It looks like an encoding problem. I have tried different conversions, but I couldn't make it work.

    If you have experience using Qt with sqlite, could you please show me an example?

    Thank you very much!

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      I would recommend to use Qt's SQL classes for storing and retrieving data. They should handle the conversion pretty good and you can operate on QStrings directly. The SQLite driver of Qt should be available with all binary installations.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved