Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Could not load Spatialite extension in QT5.9
Hi, I am trying to load Spatialite as extension in Qt, I have done that before with Qt4.8, but I failed with the QT5.9.
I changed the sqlite.pri by removing "SQLITE_OMIT_LOAD_EXTENSION", and I did some change on the sqlite.c by removing the "#define SQLITE_OMIT_LOAD_EXTENSION 1", and adding "#define SQLITE_ENABLE_LOAD_EXTENSION 1".
I also add the following lines to openDatabase(....):
Now the "requet.setQuery("SELECT load_extension('spatialite')", dbProject);" function is recognized, but I got this message:
error "The specified procedure could not be found.\r\nUnable to fetch row"
If I take a look on my debug output in MSVC14, I can see that the spatialite.dll and all its dependencies are loaded.
Notice: I tested this with my Spatialite and also the mod_spatialite that I download form their website.
Any ideas about this problem?
Thanks in advance.
The problem was with my compiled library (still i don't know why?), and also with the mod_spatialite that I downloaded. This last one when we use it with the visual studio need a replacement for the libstdc++_64-6.dll because it will cause crash.
My problem was here, the one that I used was not the good one, and was causing the The specified procedure could not be found, so I downloaded the x86_64-5.3.0-release-win32-seh-rt_v4-rev0 and I used the libstdc++-6.dll (I changed the name to libstdc++_64-6.dll) with the libgcc_s_seh-1.dll. I also changed the libxml2-2.dll with another one that I compiled before.
Then I changed the qSqlite pluginn as follow:
- open the "Qt5.9.0\5.9\Src\qtbase\src\3rdparty\sqlite" folder and change the sqlite3.c as following:
1- comment or remove the "#define SQLITE_OMIT_LOAD_EXTENSION 1"
#ifndef SQLITE_ENABLE_LOAD_EXTENSION #define SQLITE_ENABLE_LOAD_EXTENSION 1 #endif
3- go the "static int openDatabase( const char *zFilename,sqlite3 **ppDb, unsigned int flags, const char *zVfs)" function and add "| SQLITE_LoadExtFunc" to SQLITE_ENABLE_LOAD_EXTENSION as following:
#ifdef SQLITE_ENABLE_LOAD_EXTENSION | SQLITE_LoadExtension | SQLITE_LoadExtFunc #endif
compile your plugin again using your compiler ( nmake in my case) in Qt5.9.0\5.9\Src\qtbase\src\plugins\sqldrivers\sqlite\sqlite.pro
call the following code to load your spatialite:
QSqlQueryModel sql; sql.setQuery("SELECT load_extension('mod_spatialite')", db);
Ferni last edited by
Hi @MCA4213 ! I'm trying to do exactly the same but for Android. I was struggling to compile qSqlite plugin. I followed all your steps and now I have my qSqlite plugin well compiled.
I took from here a precompiled spatialite version for Android and then in Qt I run
QSqlQuery spatialiteSqlQuery(db); spatialiteSqlQuery.prepare("SELECT load_extension(\"libjsqlite\")");
but I'm still getting an error and I cannot load spatialite extension.
QSqlError("1", "Unable to fetch row", "not authorized")
Could you give me some help? Am I doing something wrong?
@Ferni , I don't have experiance on android, but :
did you make the changes on the sqlite3 file ( in my case sqlite3.c)? by removing the omit definition and altering the enable extension by:" | SQLITE_LoadExtFunc" (change the existing one)?
The not authorized error is generated when the omit definition is enabled, or the SQLITE_LoadExtFunc has not been added.
you can find some other details on my discussion on the stackoverflow: [https://stackoverflow.com/questions/44427868/could-not-load-spatialite-extension-in-qsqlite-qt-5-9](link url)
Ferni last edited by
hey @MCA4213 , thanks!! I'm pretty sure that I set all the corresponding flags but I will check again.