The answer is already here, but not written explicitly. THE call that makes the difference between crash and no crash is sqlite3_open. Apparently having the sqlite3.dll plugin on one side and the sqlite3.c compiled in on the other (to be able to call any of the sqlite3 API directly messes up or misses some init. So basically what is needed is:
1. Include sqlite code (.c and .h files) in your project
2. Use this snippet after m_Database.open()::
QVariant v
= m_Database.
driver()->handle
();
if (v.isValid() && strcmp(v.typeName(), "sqlite3*") == 0) {
// v.data() returns a pointer to the handle
sqlite3 *handle = *static_cast<sqlite3 **>(v.data());
if (handle != 0) { // check that it is not NULL
sqlite3 *p; //without this there is a crash.
int result = sqlite3_open( ":memory:", &p );
if (result == SQLITE_OK) {
sqlite3_close(p);
//call any API you need on handle.
} else
qDebug() << "Could not sqlite3_open p" << result;
} else {
qDebug() << "Could not get sqlite handle";
}
} else {
qDebug() << "handle variant returned typename " << v.typeName();
}
QVariant v = m_Database.driver()->handle();
if (v.isValid() && strcmp(v.typeName(), "sqlite3*") == 0) {
// v.data() returns a pointer to the handle
sqlite3 *handle = *static_cast<sqlite3 **>(v.data());
if (handle != 0) { // check that it is not NULL
sqlite3 *p; //without this there is a crash.
int result = sqlite3_open( ":memory:", &p );
if (result == SQLITE_OK) {
sqlite3_close(p);
//call any API you need on handle.
} else
qDebug() << "Could not sqlite3_open p" << result;
} else {
qDebug() << "Could not get sqlite handle";
}
} else {
qDebug() << "handle variant returned typename " << v.typeName();
}
To copy to clipboard, switch view to plain text mode
Bookmarks