【问题标题】:Trouble with encoding passing a QString to sqlite3_open将 QString 传递给 sqlite3_open 的编码问题
【发布时间】:2019-02-04 22:30:49
【问题描述】:

我正在尝试将 sqlite3 库与 Qt 一起使用。

我的数据库路径存储在QString 中。由于sqlite3_open 想要const char*,我尝试执行以下操作:

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

收效甚微。如果我使用

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

他们都给了我相同的(正确的)路径。但 SQLite3 似乎不接受它,因为我看到正在创建一个新文件:hЮUUU。此外,我连接的数据库显然是空的,因为 SQLite3 似乎正在连接到一个新文件。

有什么想法吗?请建议(:

【问题讨论】:

    标签: c++ qt sqlite


    【解决方案1】:

    Qt 有自己的 sqlite 实现,可以通过 QObjects 检查稳定地工作:http://katecpp.github.io/sqlite-with-qt/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多