Thomas Kowalski
Thomas Kowalski

Reputation: 2184

Trouble with encoding passing a QString to sqlite3_open

I'm trying to use the sqlite3 library with Qt.

I have my database path stored in a QString. Since sqlite3_open wants a const char*, I tried doing the following:

const QString qpath = whateverGivesIt();
const char* path = qpath.toUtf8().constData();
sqlite3_open(path, &connection);

With little success. If I use

qDebug() << qpath;
qDebug() << path;

Both of them give me the same (right) path. But SQLite3 seems not to be accepting it, since I see a new file being created: hЮUUU. Also, the database to which I'm connected is of obviously empty, as it seems that SQLite3 is connecting to a new file.

Any ideas? Please suggest (:

Upvotes: 0

Views: 39

Answers (1)

Spinkoo
Spinkoo

Reputation: 2080

Qt has its own implementation for sqlite which works in a stable way with QObjects check : http://katecpp.github.io/sqlite-with-qt/

Upvotes: 1

Related Questions