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. Cannot connect to databases, Driver not loaded error.

Cannot connect to databases, Driver not loaded error.

Scheduled Pinned Locked Moved Solved General and Desktop
18 Posts 4 Posters 6.6k Views 2 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #9

    Did you build your plugin for both debug and release ?

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    M 1 Reply Last reply
    0
    • H Offline
      H Offline
      Homer2000
      wrote on last edited by
      #10

      need dynamic lib for mysql. For linux it's libmysqlclient.so.16 or libmysqlclient.so.18 for your target platform.

      1 Reply Last reply
      0
      • SGaistS SGaist

        Did you build your plugin for both debug and release ?

        M Offline
        M Offline
        mleoni
        wrote on last edited by
        #11

        @SGaist I built just one, with the default configuration. I will check which one when I get back to my home pc. What difference does it make? Could it work with one but not the other one?

        @Homer2000 I am using a shared library, except my distribution [like many others] now uses MariaDB as a replacement for MySQL, so I link to libmariadb.so or something similar

        H 1 Reply Last reply
        0
        • M mleoni

          @SGaist I built just one, with the default configuration. I will check which one when I get back to my home pc. What difference does it make? Could it work with one but not the other one?

          @Homer2000 I am using a shared library, except my distribution [like many others] now uses MariaDB as a replacement for MySQL, so I link to libmariadb.so or something similar

          H Offline
          H Offline
          Homer2000
          wrote on last edited by
          #12

          @mleoni said in Cannot connect to databases, Driver not loaded error.:

          MariaDB

          MariaDB use libqsqlmysql plugin?

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #13

            @Homer2000 No, by default the Qt MySQL plugin links against the MySQL client libraries.

            You can build it to use MariaDB though.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1
            • M Offline
              M Offline
              mleoni
              wrote on last edited by
              #14

              Ok, I found out what I was doing wrong.
              The code that I was using is

              QSqlDatabase db;
              db.addDatabase("QMYSQL");
              

              and it was giving me the error above, whereas the correct way to do it is

              QSqlDatabase db;
              db = QSqlDatabase::addDatabase("QMYSQL");
              

              and with this code it works fine.

              I don't know why this is the case, I guess today I just learnt something new on Qt, thanks for the help everyboody!

              1 Reply Last reply
              1
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #15

                @mleoni said in Cannot connect to databases, Driver not loaded error.:

                I don't know why this is the case,

                Because QSqlDatabase::addDatabase() is a static function - no Qt magic here.

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                1
                • M Offline
                  M Offline
                  mleoni
                  wrote on last edited by
                  #16

                  I see, so my mistake was letting the returned value go lost. Thanks for clarifying this!

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #17

                    Please take the time to read the QSqlDatabase documentation. It shows how to use it properly.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      mleoni
                      wrote on last edited by
                      #18

                      Thanks for the reference!

                      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