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. Could not load Spatialite extension in QT5.9
Qt 6.11 is out! See what's new in the release blog

Could not load Spatialite extension in QT5.9

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 4.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.
  • M Offline
    M Offline
    MCA4213
    wrote on last edited by
    #1

    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(....):
    #if defined(SQLITE_ENABLE_LOAD_EXTENSION)
    | SQLITE_LoadExtension|SQLITE_LoadExtFunc
    #endif

    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.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MCA4213
      wrote on last edited by
      #2

      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"

      2-add:

      #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);
      
      1 Reply Last reply
      0
      • FerniF Offline
        FerniF Offline
        Ferni
        wrote on last edited by
        #3

        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?

        Thanks,
        Fernando

        M 1 Reply Last reply
        0
        • FerniF Ferni

          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?

          Thanks,
          Fernando

          M Offline
          M Offline
          MCA4213
          wrote on last edited by
          #4

          @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)

          1 Reply Last reply
          0
          • FerniF Offline
            FerniF Offline
            Ferni
            wrote on last edited by
            #5

            hey @MCA4213 , thanks!! I'm pretty sure that I set all the corresponding flags but I will check again.

            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