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. Unable to connect to local Mysql database in 64bit but able to do so under 32bit
QtWS25 Last Chance

Unable to connect to local Mysql database in 64bit but able to do so under 32bit

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 3 Posters 1.4k 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.
  • J Offline
    J Offline
    JohnFrom
    wrote on 16 Jul 2018, 03:38 last edited by JohnFrom
    #1

    Greetings.

    I cannot connect with my Qt app to local mysql database in win7 64 bit, but in 32bit it is done perfectly fine.

    Here is the code:

    QSqlDatabase db;

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

    db.setDatabaseName("myserver");
    
    db.setHostName("localhost");// tried 127.0.0.1 too, same symptoms
    db.setUserName("******");
    db.setPassword("******");
    db.setPort(3306);
    

    And I don't know if an error code cold be obtained because I haven't find any means to do that.

    Any suggestions? What should I do to fix this?

    A 1 Reply Last reply 16 Jul 2018, 03:52
    0
    • J JohnFrom
      16 Jul 2018, 03:38

      Greetings.

      I cannot connect with my Qt app to local mysql database in win7 64 bit, but in 32bit it is done perfectly fine.

      Here is the code:

      QSqlDatabase db;

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

      db.setDatabaseName("myserver");
      
      db.setHostName("localhost");// tried 127.0.0.1 too, same symptoms
      db.setUserName("******");
      db.setPassword("******");
      db.setPort(3306);
      

      And I don't know if an error code cold be obtained because I haven't find any means to do that.

      Any suggestions? What should I do to fix this?

      A Offline
      A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on 16 Jul 2018, 03:52 last edited by
      #2

      hi @JohnFrom,

      have you built the Qt MYSQL plugin for both architectures?

      do you see any error in the console when your app is running?

      regards

      Qt has to stay free or it will die.

      J 1 Reply Last reply 16 Jul 2018, 04:45
      3
      • A aha_1980
        16 Jul 2018, 03:52

        hi @JohnFrom,

        have you built the Qt MYSQL plugin for both architectures?

        do you see any error in the console when your app is running?

        regards

        J Offline
        J Offline
        JohnFrom
        wrote on 16 Jul 2018, 04:45 last edited by
        #3

        @aha_1980 said in Unable to connect to local Mysql database in 64bit but able to do so under 32bit:

        hi @JohnFrom,

        have you built the Qt MYSQL plugin for both architectures?

        Probably not - I'm maintaining someone else's code, and now I think about it, I have not factored in which target system I am building for, that is, I simply generated my app (you know, the .exe file) using the make project from the "build" menu.

        I'm not exactly sure how to build that plugin at this point.

        I'm a rookie on this, there probably are a lot of things I haven't thought about.

        Oh, one more thing - the app can run pretty well on MY 64 bit win7 machine. The problem appears consistently on a newly installed win7 64bit, suggesting that there may be something I installed on my machine which enabled it to run properly.

        Witht hat in mind, I tried uninstalling a lot of stuff to produce the same erroneous result, but couldn't. I tried install Qt on that freshly installed machine, but couldn't solve the problem. Quite frustrating.

        do you see any error in the console when your app is running?

        No not really, there isn't a console to begin with. It's not a console app and the only warning message box I got was "unable to connect to database", something coded in the program itself.

        A 1 Reply Last reply 16 Jul 2018, 05:48
        0
        • J JohnFrom
          16 Jul 2018, 04:45

          @aha_1980 said in Unable to connect to local Mysql database in 64bit but able to do so under 32bit:

          hi @JohnFrom,

          have you built the Qt MYSQL plugin for both architectures?

          Probably not - I'm maintaining someone else's code, and now I think about it, I have not factored in which target system I am building for, that is, I simply generated my app (you know, the .exe file) using the make project from the "build" menu.

          I'm not exactly sure how to build that plugin at this point.

          I'm a rookie on this, there probably are a lot of things I haven't thought about.

          Oh, one more thing - the app can run pretty well on MY 64 bit win7 machine. The problem appears consistently on a newly installed win7 64bit, suggesting that there may be something I installed on my machine which enabled it to run properly.

          Witht hat in mind, I tried uninstalling a lot of stuff to produce the same erroneous result, but couldn't. I tried install Qt on that freshly installed machine, but couldn't solve the problem. Quite frustrating.

          do you see any error in the console when your app is running?

          No not really, there isn't a console to begin with. It's not a console app and the only warning message box I got was "unable to connect to database", something coded in the program itself.

          A Offline
          A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on 16 Jul 2018, 05:48 last edited by
          #4

          hi @JohnFrom,

          1. just google for 'qt mysql plugin'
          2. if you run you program from the IDE or command line in debug mode, you will see the warnings

          Qt has to stay free or it will die.

          J 1 Reply Last reply 16 Jul 2018, 06:03
          0
          • A aha_1980
            16 Jul 2018, 05:48

            hi @JohnFrom,

            1. just google for 'qt mysql plugin'
            2. if you run you program from the IDE or command line in debug mode, you will see the warnings
            J Offline
            J Offline
            JohnFrom
            wrote on 16 Jul 2018, 06:03 last edited by
            #5

            @aha_1980 said in Unable to connect to local Mysql database in 64bit but able to do so under 32bit:

            hi @JohnFrom,

            1. just google for 'qt mysql plugin'

            2 things:

            1. there appears to be a ready-made project in the "plugin" folder of my Qt installation directory. But If I open it up with QT and try to build it, the "mySql.h" is missing, and I don't know which version I should download from the mysql site. If I use the latest source code from mysql, the compilation will result in more missing files because I'm using the wrong mysql.h.

            2. It seems that I also need to build a 64bit app for win7 64. And to do that I need to manually build a 64 bit Qt in Visual studio 64??? That sounds rather unreasonable?

            Could you be kind enough to help me a bit further? For starters where should I find the mysql plugin source code that is complete?

            A 1 Reply Last reply 16 Jul 2018, 06:54
            0
            • J JohnFrom
              16 Jul 2018, 06:03

              @aha_1980 said in Unable to connect to local Mysql database in 64bit but able to do so under 32bit:

              hi @JohnFrom,

              1. just google for 'qt mysql plugin'

              2 things:

              1. there appears to be a ready-made project in the "plugin" folder of my Qt installation directory. But If I open it up with QT and try to build it, the "mySql.h" is missing, and I don't know which version I should download from the mysql site. If I use the latest source code from mysql, the compilation will result in more missing files because I'm using the wrong mysql.h.

              2. It seems that I also need to build a 64bit app for win7 64. And to do that I need to manually build a 64 bit Qt in Visual studio 64??? That sounds rather unreasonable?

              Could you be kind enough to help me a bit further? For starters where should I find the mysql plugin source code that is complete?

              A Offline
              A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on 16 Jul 2018, 06:54 last edited by
              #6

              Hi @JohnFrom,

              Please follow the instructions here: http://doc.qt.io/qt-5/sql-driver.html#how-to-build-the-qmysql-plugin-on-windows You will need to install MySQL to have the header file available, I don't think you need the source code, just the header and lib files.

              And you don't need to build Qt from source, there are several precompiled versions for the diverse compilers available.

              Regards

              Qt has to stay free or it will die.

              J 1 Reply Last reply 16 Jul 2018, 07:26
              1
              • A aha_1980
                16 Jul 2018, 06:54

                Hi @JohnFrom,

                Please follow the instructions here: http://doc.qt.io/qt-5/sql-driver.html#how-to-build-the-qmysql-plugin-on-windows You will need to install MySQL to have the header file available, I don't think you need the source code, just the header and lib files.

                And you don't need to build Qt from source, there are several precompiled versions for the diverse compilers available.

                Regards

                J Offline
                J Offline
                JohnFrom
                wrote on 16 Jul 2018, 07:26 last edited by JohnFrom
                #7

                @aha_1980 said in Unable to connect to local Mysql database in 64bit but able to do so under 32bit:

                Hi @JohnFrom,

                Please follow the instructions here: http://doc.qt.io/qt-5/sql-driver.html#how-to-build-the-qmysql-plugin-on-windows You will need to install MySQL to have the header file available, I don't think you need the source code, just the header and lib files.

                And you don't need to build Qt from source, there are several precompiled versions for the diverse compilers available.

                Regards

                Hey thanks! I'll see what I can do!

                Just one last thing - I SHOULD compile a 64bit version of my APP for a 64 bit system right? Or is it rather unnecessary?

                A 1 Reply Last reply 16 Jul 2018, 07:35
                0
                • J JohnFrom
                  16 Jul 2018, 07:26

                  @aha_1980 said in Unable to connect to local Mysql database in 64bit but able to do so under 32bit:

                  Hi @JohnFrom,

                  Please follow the instructions here: http://doc.qt.io/qt-5/sql-driver.html#how-to-build-the-qmysql-plugin-on-windows You will need to install MySQL to have the header file available, I don't think you need the source code, just the header and lib files.

                  And you don't need to build Qt from source, there are several precompiled versions for the diverse compilers available.

                  Regards

                  Hey thanks! I'll see what I can do!

                  Just one last thing - I SHOULD compile a 64bit version of my APP for a 64 bit system right? Or is it rather unnecessary?

                  A Offline
                  A Offline
                  aha_1980
                  Lifetime Qt Champion
                  wrote on 16 Jul 2018, 07:35 last edited by
                  #8

                  @JohnFrom said in Unable to connect to local Mysql database in 64bit but able to do so under 32bit:

                  Just one last thing - I SHOULD compile a 64bit version of my APP for a 64 bit system right? Or is it rather unnecessary?

                  Windows x64 executes 32 bit apps without problem (tm). So no, it is not absolutely necessary.

                  Even on Linux it is possible to execute 32 bit programs on a 64 bit system - it's usually more work.

                  I can't tell for Mac.

                  Regards

                  Qt has to stay free or it will die.

                  J 1 Reply Last reply 16 Jul 2018, 11:05
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 16 Jul 2018, 09:13 last edited by
                    #9

                    Hi,

                    Don't bother trying to build your application for 32bit on macOS.

                    AFAIK, High Sierra is the last version of macOS where you'll be able to run 32bit application.

                    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
                    • A aha_1980
                      16 Jul 2018, 07:35

                      @JohnFrom said in Unable to connect to local Mysql database in 64bit but able to do so under 32bit:

                      Just one last thing - I SHOULD compile a 64bit version of my APP for a 64 bit system right? Or is it rather unnecessary?

                      Windows x64 executes 32 bit apps without problem (tm). So no, it is not absolutely necessary.

                      Even on Linux it is possible to execute 32 bit programs on a 64 bit system - it's usually more work.

                      I can't tell for Mac.

                      Regards

                      J Offline
                      J Offline
                      JohnFrom
                      wrote on 16 Jul 2018, 11:05 last edited by
                      #10

                      @aha_1980 said in Unable to connect to local Mysql database in 64bit but able to do so under 32bit:

                      @JohnFrom said in Unable to connect to local Mysql database in 64bit but able to do so under 32bit:

                      Just one last thing - I SHOULD compile a 64bit version of my APP for a 64 bit system right? Or is it rather unnecessary?

                      Windows x64 executes 32 bit apps without problem (tm). So no, it is not absolutely necessary.

                      Even on Linux it is possible to execute 32 bit programs on a 64 bit system - it's usually more work.

                      I can't tell for Mac.

                      Regards

                      Thanks! I'm only building for win7 64bit though.

                      1 Reply Last reply
                      0
                      • J Offline
                        J Offline
                        JohnFrom
                        wrote on 17 Jul 2018, 09:18 last edited by
                        #11

                        Lass and Gents:

                        I;ve figured it all out. Thanks to aha_1980, I decided that it's because of this:

                        Debugging starts
                        QSqlDatabase: QMYSQL driver not loaded
                        QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
                        Unable to open database
                        Debugging has finished

                        So it's most likely that whatever "libmysql.dll" that came with the system or mysql installtion program isn't compatible with my app.

                        What I did is that I copy and replaced the "libmysql.dll" in my c:\windows with a correct version and viola! It's now up and kicking!

                        Thank you all!

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 17 Jul 2018, 09:52 last edited by
                          #12

                          Never put anything in C:\Windows. As you have seen the effect: application will use that version of the .dll rather than the one they were meant to use.

                          Doing that, you might be breaking another application on your system.

                          You should always provide all the .dlls your application need in the proper place(s) of your installation tree.

                          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
                          2

                          1/12

                          16 Jul 2018, 03:38

                          • Login

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