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. Connect to MYSQL failed in Qt
Forum Updated to NodeBB v4.3 + New Features

Connect to MYSQL failed in Qt

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt6c++mysqlmysql server
33 Posts 4 Posters 6.6k 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.
  • E ELEMENTICY
    7 May 2021, 05:52

    @Christian-Ehrlicher i do,

    win32:CONFIG(release, debug|release): LIBS += -L$$PWD/lib/libmysql
    else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/lib/libmysqld
    else:unix: LIBS += -L$$PWD/lib/libmysql
    

    And yea,use qt sql it just give like 11 error
    And if i use official mysql mysql.h,it only give 2 error which is undefine

    And yea,or i need to change my profile's lib code to this?

    win32:CONFIG(release, debug|release): LIBS += -L$$PWD/lib/libmysql.lib
    else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/lib/libmysqld.lib
    else:unix: LIBS += -L$$PWD/lib/libmysql.lib
    
    C Offline
    C Offline
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on 7 May 2021, 11:13 last edited by
    #17

    @ELEMENTICY said in Connect to MYSQL failed in Qt:

    And yea,use qt sql it just give like 11 error

    What does this mean?

    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
    • E ELEMENTICY
      7 May 2021, 11:12

      @SGaist my current profile code:

      win32:CONFIG(release, debug|release): LIBS += -L$$PWD/lib/ -llibmysql
      else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/lib/ -llibmysqld
      else:unix: LIBS += -L$$PWD/lib/ -llibmysql
      

      documentation:

      LIBS += -L"3rdparty/CatWhisperer/lib" -lCatWhisperer
      

      i got this error:
      :-1: error: error: cannot find -llibmysql

      proof that path exists:
      Screenshot 2021-05-07 191143.png

      S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 7 May 2021, 11:14 last edited by
      #18

      @ELEMENTICY did you read what I wrote ? No "lib" prefix.

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

      E 2 Replies Last reply 7 May 2021, 11:16
      0
      • S SGaist
        7 May 2021, 11:14

        @ELEMENTICY did you read what I wrote ? No "lib" prefix.

        E Offline
        E Offline
        ELEMENTICY
        wrote on 7 May 2021, 11:16 last edited by
        #19

        @SGaist
        current code:

        win32:CONFIG(release, debug|release): LIBS += -L$$PWD/lib/libmysql
        else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/lib/libmysqld
        else:unix: LIBS += -L$$PWD/lib/libmysql
        

        idk if i misunderstanded what u mean,but it still give error ;/
        or u mean i have to remove that -L

        S 1 Reply Last reply 7 May 2021, 18:43
        0
        • S SGaist
          7 May 2021, 11:14

          @ELEMENTICY did you read what I wrote ? No "lib" prefix.

          E Offline
          E Offline
          ELEMENTICY
          wrote on 7 May 2021, 11:17 last edited by
          #20

          @SGaist and yea i dont know if its because im working on a android app,so it doesnt work

          S 1 Reply Last reply 7 May 2021, 18:44
          0
          • E ELEMENTICY
            7 May 2021, 11:16

            @SGaist
            current code:

            win32:CONFIG(release, debug|release): LIBS += -L$$PWD/lib/libmysql
            else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/lib/libmysqld
            else:unix: LIBS += -L$$PWD/lib/libmysql
            

            idk if i misunderstanded what u mean,but it still give error ;/
            or u mean i have to remove that -L

            S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 7 May 2021, 18:43 last edited by
            #21

            @ELEMENTICY said in Connect to MYSQL failed in Qt:

            @SGaist
            current code:

            win32:CONFIG(release, debug|release): LIBS += -L$$PWD/lib/libmysql
            else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/lib/libmysqld
            else:unix: LIBS += -L$$PWD/lib/libmysql
            

            idk if i misunderstanded what u mean,but it still give error ;/
            or u mean i have to remove that -L

            You have to understand what -L and -l each do. I have already explained that before. So please re-read the corresponding answers.

            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
            • E ELEMENTICY
              7 May 2021, 11:17

              @SGaist and yea i dont know if its because im working on a android app,so it doesnt work

              S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 7 May 2021, 18:44 last edited by
              #22

              @ELEMENTICY said in Connect to MYSQL failed in Qt:

              @SGaist and yea i dont know if its because im working on a android app,so it doesnt work

              Oracle does not provide pre-built binaries for Android.

              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
              • E Offline
                E Offline
                ELEMENTICY
                wrote on 8 May 2021, 05:07 last edited by ELEMENTICY 5 Aug 2021, 05:08
                #23

                @SGaist dude,im so tired...
                Can you pleaseee write the 3 lines of code for me?
                Please... i hope after you see this message,you wont just ignore and think i never hard work on it..But im tired for just add a simple library already...
                It will be the BEST help for me

                My current code...

                win32:CONFIG(release, debug|release): LIBS += $$PWD/lib/ -llibmysql
                else:win32:CONFIG(debug, debug|release): LIBS += $$PWD/lib/ -llibmysqld
                else:unix: LIBS += $$PWD/lib/ -llibmysql
                

                Error:
                :-1: error: error: cannot open C:/Users/ELEMENT/Documents/PosSystem/Pos/lib/: Permission denied
                I opened QT Creator with Administrator,still same...

                I also tried..

                win32:CONFIG(release, debug|release): LIBS += $$PWD/lib/libmysql
                else:win32:CONFIG(debug, debug|release): LIBS += $$PWD/lib/libmysqld
                else:unix: LIBS += $$PWD/lib/libmysql
                

                Error:
                :-1: error: no such file or directory: 'C:/Users/ELEMENT/Documents/PosSystem/Pos/lib/libmysql' clang++: error: no such file or directory: 'C:/Users/ELEMENT/Documents/PosSystem/Pos/lib/libmysql' make: *** [Makefile:79: libPos_x86_64.so] Error 1
                Seems like that one is the wrong way to do without adding -l

                appreciate it...

                1 Reply Last reply
                0
                • E Offline
                  E Offline
                  ELEMENTICY
                  wrote on 8 May 2021, 05:18 last edited by
                  #24

                  @SGaist I removed:

                  win32:CONFIG(release, debug|release): LIBS += $$PWD/lib/ -llibmysql
                  else:win32:CONFIG(debug, debug|release): LIBS += $$PWD/lib/ -llibmysqld
                  else:unix: LIBS += $$PWD/lib/ -llibmysql
                  

                  And tried only

                  LIBS += -L"lib" -llibmysql
                  

                  Still error:
                  :-1: error: error: cannot find -llibmysql

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 8 May 2021, 06:38 last edited by
                    #25

                    "Drop the lib prefix": -lmysql

                    To repeat myself: Oracle does not provide pre-built binaries for Android.

                    Also, @Christian-Ehrlicher already asked you several times: what exact error did you get with the QtSql module ?

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

                    E 1 Reply Last reply 8 May 2021, 10:14
                    1
                    • S SGaist
                      8 May 2021, 06:38

                      "Drop the lib prefix": -lmysql

                      To repeat myself: Oracle does not provide pre-built binaries for Android.

                      Also, @Christian-Ehrlicher already asked you several times: what exact error did you get with the QtSql module ?

                      E Offline
                      E Offline
                      ELEMENTICY
                      wrote on 8 May 2021, 10:14 last edited by ELEMENTICY 5 Aug 2021, 10:15
                      #26

                      @SGaist ok its weird,it now dont give any error.But its EXCELENT!
                      But it unable to connect to Server
                      My code:

                      QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
                              db.setHostName("localhost");
                              db.setDatabaseName("pos");
                              db.setUserName("root");
                      
                              if (!db.open()){
                                  ui->error->setText("Oops,Unable to connect to Server!Please contact your Administrator for help.");
                              }
                      

                      Includes:

                      #include <QtSql/QSql>
                      #include <QtSql/QSqlDatabase>
                      #include <QtSql/QSqlDriver>
                      #include <QtSql/QSqlQuery>
                      

                      and i also added sql to Qt in Profile

                      QT       += core gui sql
                      
                      E 1 Reply Last reply 8 May 2021, 10:20
                      0
                      • E ELEMENTICY
                        8 May 2021, 10:14

                        @SGaist ok its weird,it now dont give any error.But its EXCELENT!
                        But it unable to connect to Server
                        My code:

                        QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
                                db.setHostName("localhost");
                                db.setDatabaseName("pos");
                                db.setUserName("root");
                        
                                if (!db.open()){
                                    ui->error->setText("Oops,Unable to connect to Server!Please contact your Administrator for help.");
                                }
                        

                        Includes:

                        #include <QtSql/QSql>
                        #include <QtSql/QSqlDatabase>
                        #include <QtSql/QSqlDriver>
                        #include <QtSql/QSqlQuery>
                        

                        and i also added sql to Qt in Profile

                        QT       += core gui sql
                        
                        E Offline
                        E Offline
                        ELEMENTICY
                        wrote on 8 May 2021, 10:20 last edited by
                        #27

                        @ELEMENTICY im sure i entered correct server info

                        J 1 Reply Last reply 8 May 2021, 10:59
                        0
                        • E ELEMENTICY
                          8 May 2021, 10:20

                          @ELEMENTICY im sure i entered correct server info

                          J Offline
                          J Offline
                          JonB
                          wrote on 8 May 2021, 10:59 last edited by JonB 5 Aug 2021, 10:59
                          #28

                          @ELEMENTICY
                          So your root user has no password to connect to MySQL?

                          If db.open() fails, why don't you print out db.lastError() into your error message?

                          E 1 Reply Last reply 8 May 2021, 13:08
                          0
                          • S Offline
                            S Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on 8 May 2021, 11:22 last edited by
                            #29

                            Do you have a run time warning stating that the plugin cannot be loaded ?

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

                            E 1 Reply Last reply 8 May 2021, 13:08
                            0
                            • S SGaist
                              8 May 2021, 11:22

                              Do you have a run time warning stating that the plugin cannot be loaded ?

                              E Offline
                              E Offline
                              ELEMENTICY
                              wrote on 8 May 2021, 13:08 last edited by
                              #30

                              @SGaist yes there is

                              S 1 Reply Last reply 8 May 2021, 18:52
                              0
                              • J JonB
                                8 May 2021, 10:59

                                @ELEMENTICY
                                So your root user has no password to connect to MySQL?

                                If db.open() fails, why don't you print out db.lastError() into your error message?

                                E Offline
                                E Offline
                                ELEMENTICY
                                wrote on 8 May 2021, 13:08 last edited by
                                #31

                                @JonB no password,only root

                                1 Reply Last reply
                                0
                                • E ELEMENTICY
                                  8 May 2021, 13:08

                                  @SGaist yes there is

                                  S Offline
                                  S Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on 8 May 2021, 18:52 last edited by
                                  #32

                                  @ELEMENTICY said in Connect to MYSQL failed in Qt:

                                  @SGaist yes there is

                                  Then build the plugin following the instructions from the
                                  documentation.

                                  As I already noted: there's no prebuilt Oracle MySQL library for Androïd. You will have to build the MariaDB libraries and then the plugin for that platform.

                                  As a side note: if you intend for your application to access that database through internet, you should reconsider that. It's a really bad idea to put a database in front of internet.

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

                                  E 1 Reply Last reply 9 May 2021, 09:33
                                  1
                                  • S SGaist
                                    8 May 2021, 18:52

                                    @ELEMENTICY said in Connect to MYSQL failed in Qt:

                                    @SGaist yes there is

                                    Then build the plugin following the instructions from the
                                    documentation.

                                    As I already noted: there's no prebuilt Oracle MySQL library for Androïd. You will have to build the MariaDB libraries and then the plugin for that platform.

                                    As a side note: if you intend for your application to access that database through internet, you should reconsider that. It's a really bad idea to put a database in front of internet.

                                    E Offline
                                    E Offline
                                    ELEMENTICY
                                    wrote on 9 May 2021, 09:33 last edited by
                                    #33

                                    @SGaist ok lemme try,if i understand what documentation say lol

                                    1 Reply Last reply
                                    0

                                    26/33

                                    8 May 2021, 10:14

                                    • Login

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