Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. Issues with QMYSQL driver
Forum Updated to NodeBB v4.3 + New Features

Issues with QMYSQL driver

Scheduled Pinned Locked Moved Unsolved Installation and Deployment
4 Posts 3 Posters 555 Views
  • 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
    Mocha Shakea Khan
    wrote on last edited by Mocha Shakea Khan
    #1

    I want to connect qt with mysql databse; i watched this video https://www.youtube.com/watch?v=0quVy31AOw4 and followed the steps. Here's my code.

    I included qtsql/qsqldatabase and qdebug in the header file.

    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    db.setHostName("127.0.0.1");
    db.setDatabaseName("slmp");
    db.setUserName("root");
    db.setPassword("");

       if (db.open())
           ui->db_label->setText("Connected...");
       else {
           ui->db_label->setText("Failed to connect");
       }
    

    When i execute this code i of course get the failed to connect text and this statement appears in the output:

    19:02:01: Starting D:\workspace\Qt\build-LMS-Desktop_Qt_5_12_3_MSVC2017_32bit-Debug\debug\LMS.exe ...

    QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7

    The video states to copy libmysql.dll from the mysql connector c file into the mingw but i still got the same output. Then i noticed the output is building from the mscv2017_32 file so i copied the libmysql.dll there and after running the program and failing to connect i got this output:

    19:07:16: Starting D:\workspace\Qt\build-LMS-Desktop_Qt_5_12_3_MSVC2017_32bit-Debug\debug\LMS.exe ...

    19:07:21: D:/workspace/Qt/build-LMS-Desktop_Qt_5_12_3_MSVC2017_32bit-Debug/debug/LMS.exe exited with code 0

    I'm not sure if the driver is loaded correctly but there's something wrong with my code or if it's something else. I spent the last 2 days searching for a solution with no avail.

    1 Reply Last reply
    0
    • KillerSmathK Offline
      KillerSmathK Offline
      KillerSmath
      wrote on last edited by
      #2

      @Mocha-Shakea-Khan

      A good way to check if your Mysql Driver is working, is trying to run the Sql Browser Example on Qt Project.
      It will notify you if something is wrong or will add the connection on List of connections
      0_1555807015385_sql-browser.gif

      @Computer Science Student - Brazil
      Web Developer and Researcher
      “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mocha Shakea Khan
        wrote on last edited by
        #3

        I tried running the browser and got a message stating:

        An error occurred while opening the connection: Authentication plugin 'caching_sha2_password' cannot be loaded: The specified module could not be found. QMYSQL: Unable to connect

        JonBJ 1 Reply Last reply
        0
        • M Mocha Shakea Khan

          I tried running the browser and got a message stating:

          An error occurred while opening the connection: Authentication plugin 'caching_sha2_password' cannot be loaded: The specified module could not be found. QMYSQL: Unable to connect

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @Mocha-Shakea-Khan
          Just a thought: I note your own code is being built for 32-bit. Wherever you got the libmysql.dll etc. libraries from, did you ensure they too are 32-bit? If they are 64-bit it won't load....

          P.S.
          You don't say whether you are downloading a pre-built QMYSQL or compiling it yourself. If it's the latter, have a read of the stickied thread on this forum, https://forum.qt.io/topic/40672/how-to-create-the-plugin-of-mysql-for-qt. In either case Goggle for QMYSQL driver not loaded: there are a lot of hits for this (both on this forum & elsewhere) which may sort you out.

          1 Reply Last reply
          2

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved