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. error connecting to Mysql
Forum Updated to NodeBB v4.3 + New Features

error connecting to Mysql

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 680 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.
  • L Offline
    L Offline
    lincoln
    wrote on 12 Sept 2019, 22:20 last edited by
    #1

    good afternoon.
    I have a question regarding database, I have a database made in mysql, and when I want to connect from qt, I get an error message, that the controller was not found, and when I see the message it comes out that they are only available the sqlite, postgre and obdc drivers, maybe in the version of qt that I am using that driver is no longer available, I am using version 5.13.1 of qt, I would appreciate your comments, I leave the code I made to connect to the base of data, I also leave a screenshot of the error message.

    codigo:

    #include "principalclass.h"
    #include "ui_principalclass.h"
    #include <QSqlDatabase>
    #include <QSqlError>
    #include <QMessageBox>
    
    PrincipalClass::PrincipalClass(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::PrincipalClass)
    {
        ui->setupUi(this);
        QSqlDatabase db=QSqlDatabase::addDatabase("QMYSQL");
        if(!db.isDriverAvailable("QMYSQL"))
          {
            QMessageBox::critical(this,qApp->applicationName(),
                                  "driver was not found.\n"+db.lastError().text());
            return;
          }
        db.setPort(3306);
        db.setHostName("localhost");
        db.setDatabaseName("ejemplo");
        db.setUserName("root");
        db.setPassword("2311046");
        if(!db.open())
          {
            QMessageBox::critical(this,qApp->applicationName(),
                                  "error opening database.\n"+db.lastError().text());
            return;
          }
        QMessageBox::information(this,qApp->applicationName(),
                                 "Todo bien");
    }
    
    PrincipalClass::~PrincipalClass()
    {
        delete ui;
    }
    
    
    

    0_1568326831093_55308d63-b8ab-43b1-acaa-b5663b3c0432-image.png

    Solitary wolf

    J 1 Reply Last reply 12 Sept 2019, 22:46
    0
    • L lincoln
      12 Sept 2019, 22:20

      good afternoon.
      I have a question regarding database, I have a database made in mysql, and when I want to connect from qt, I get an error message, that the controller was not found, and when I see the message it comes out that they are only available the sqlite, postgre and obdc drivers, maybe in the version of qt that I am using that driver is no longer available, I am using version 5.13.1 of qt, I would appreciate your comments, I leave the code I made to connect to the base of data, I also leave a screenshot of the error message.

      codigo:

      #include "principalclass.h"
      #include "ui_principalclass.h"
      #include <QSqlDatabase>
      #include <QSqlError>
      #include <QMessageBox>
      
      PrincipalClass::PrincipalClass(QWidget *parent)
          : QMainWindow(parent)
          , ui(new Ui::PrincipalClass)
      {
          ui->setupUi(this);
          QSqlDatabase db=QSqlDatabase::addDatabase("QMYSQL");
          if(!db.isDriverAvailable("QMYSQL"))
            {
              QMessageBox::critical(this,qApp->applicationName(),
                                    "driver was not found.\n"+db.lastError().text());
              return;
            }
          db.setPort(3306);
          db.setHostName("localhost");
          db.setDatabaseName("ejemplo");
          db.setUserName("root");
          db.setPassword("2311046");
          if(!db.open())
            {
              QMessageBox::critical(this,qApp->applicationName(),
                                    "error opening database.\n"+db.lastError().text());
              return;
            }
          QMessageBox::information(this,qApp->applicationName(),
                                   "Todo bien");
      }
      
      PrincipalClass::~PrincipalClass()
      {
          delete ui;
      }
      
      
      

      0_1568326831093_55308d63-b8ab-43b1-acaa-b5663b3c0432-image.png

      J Offline
      J Offline
      JonB
      wrote on 12 Sept 2019, 22:46 last edited by JonB 9 Dec 2019, 22:50
      #2

      @lincoln
      You are not configured yet to use MySQL. This comes up so often here I think there may be post, search this forum or Google for the message you see QSqlDatabase QMYSQL driver not loaded, pick a recent-ish answer, there are several. If you have to build it yourself, and you're Windows, the main stickied thread at https://forum.qt.io/topic/40672/how-to-create-the-plugin-of-mysql-for-qt may be relevant, but I think you can get it pre-compiled for Windows from somewhere.

      1 Reply Last reply
      3
      • L Offline
        L Offline
        lincoln
        wrote on 13 Sept 2019, 05:06 last edited by lincoln
        #3

        Well I take it back, my question would be, how to build the mysql driver in qt 5.13.1, I already tried to do it with the official QT documentation but I didn't get it.
        I did this

        0_1568351348652_23541bcd-551b-4733-b147-dbeec9232a5a-image.png

        0_1568351412435_1bff645f-a0ef-4d21-bde7-b91afe424234-image.png

        and there was no result, I get this.

        Solitary wolf

        1 Reply Last reply
        0
        • C Online
          C Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 13 Sept 2019, 06:17 last edited by
          #4

          Move the mysql libs to a path without spaces and try again. Or properly quote your paths or use MYSQL_INCDIR/MYSQL_LIBDIR as stated in the documentation

          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
          3
          • L Offline
            L Offline
            lincoln
            wrote on 13 Sept 2019, 17:21 last edited by
            #5

            Well friends, I tried everything and there is no result, thanks anyway.

            Solitary wolf

            1 Reply Last reply
            0
            • C Online
              C Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 13 Sept 2019, 17:35 last edited by
              #6

              @lincoln said in error connecting to Mysql:

              Well friends, I tried everything and there is no result, thanks anyway.

              What did you do? You will at least get another error message than the one above.

              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
              0
              • L Offline
                L Offline
                lincoln
                wrote on 13 Sept 2019, 20:13 last edited by
                #7

                I tried an ODBC connection but I also got an error, so I think I'll leave it there, I will try PostGresql.

                Solitary wolf

                1 Reply Last reply
                0
                • C Online
                  C Online
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on 13 Sept 2019, 20:21 last edited by
                  #8

                  @lincoln said in error connecting to Mysql:

                  I tried an ODBC connection

                  So you never tested our suggestions... good to know :(

                  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
                  0
                  • L Offline
                    L Offline
                    lincoln
                    wrote on 13 Sept 2019, 20:26 last edited by
                    #9

                    @christian-ehrlicher said in error connecting to Mysql:

                    MYSQL_INCDIR/MYSQL_LIBDIR

                    I did what they told me, but I got more errors than in the beginning, I don't even compile when I switch to MYSQL_INCDIR / MYSQL_LIBDIR, as you said, so I left it like that, I have to move forward with this since it is a job for the university, I thank you for your comments.

                    Solitary wolf

                    1 Reply Last reply
                    0

                    1/9

                    12 Sept 2019, 22:20

                    • Login

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