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. [SOLVED] First Steps and MySQL
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] First Steps and MySQL

Scheduled Pinned Locked Moved General and Desktop
13 Posts 3 Posters 7.0k 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.
  • R Offline
    R Offline
    Rondog
    wrote on last edited by
    #2

    You shouldn't need to download anything else. You do have 'QMYSQL' on the list of available drivers so the plugin is there and visible.

    This is what I have used in the past. I haven't tried it in 5.4.0 yet but I did try it in 5.3.2 and it worked.

    Note: I use the name of the database as the connection name and the first 'if' is to see if it was used previously.

    @ if(QSqlDatabase::contains(d_StartupOptions->OdbcDatabaseName))
    {
    Database = QSqlDatabase::database(d_StartupOptions->OdbcDatabaseName);
    }
    else
    {
    Database = QSqlDatabase::addDatabase(d_StartupOptions->OdbcDatabaseDriver,d_StartupOptions->OdbcDatabaseName);
    }

    Database.setDatabaseName(d_StartupOptions->OdbcDatabaseName);
    Database.setUserName(d_StartupOptions->OdbcUserName);
    Database.setHostName(d_StartupOptions->OdbcHostName);
    Database.setPassword(d_StartupOptions->OdbcPassword);
    Database.setPort(d_StartupOptions->OdbcPortNumber.toInt());

    if(Database.open())
    {
    ...
    }

    @

    Have you tried to login to the database (using a terminal window) on either (or both) windows and linux to verify it is setup properly and working?

    1 Reply Last reply
    0
    • P Offline
      P Offline
      panoramix
      wrote on last edited by
      #3

      Hello
      Am I wrong or are you using ODBC for the connection to DB?
      I'd rather use the native drivers.

      Yes, the MySQL server is working and I can connect using other tools.

      Thanks for the reply

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Rondog
        wrote on last edited by
        #4

        No. I know the variable names suggest ODBC but I am not using this anymore (too many issues across operating systems).

        You can shorten down the add database command to this:

        @
        Database = QSqlDatabase::addDatabase("QMYSQL");
        @

        The connection name would be 'defaultConnection' if not specified.

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

          Hi and welcome to devnet,

          Two things comes to mind:

          Do you have the MySQL client libraries installed on your system ?

          If yes, do you have the path to the folder containing the dlls in the PATH environment variable ?

          If no, you can update the content of that PATH in Qt Creator Run part of the Project panel.

          Hope it helps

          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
          • P Offline
            P Offline
            panoramix
            wrote on last edited by
            #6

            [quote author="SGaist" date="1419980992"]Hi and welcome to devnet,

            Two things comes to mind:

            Do you have the MySQL client libraries installed on your system ?

            If yes, do you have the path to the folder containing the dlls in the PATH environment variable ?

            If no, you can update the content of that PATH in Qt Creator Run part of the Project panel.

            Hope it helps[/quote]

            Hi SGaist , thanks for the welcome and happy new year to you

            On linux mint 17.1 I installed the package of client libraries but there is a version problem.

            On Windows I installed the package MySQL Connectors, and then I tried to copy the dll in the directory where I compiled the sample application, but I think it is not the correct way.

            What do I have to download from the website of MySQL for windows?

            1 Reply Last reply
            0
            • P Offline
              P Offline
              panoramix
              wrote on last edited by
              #7

              Hi

              Sorry but I have not given a basic information I'm using the open source version of Qt.

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

                Happy new year to you too !

                Run ldd on the Qt MySQL plugin to see what libraries it links to. I'd guess that you have something like plugin linked to version 16 of the client library and you have version 18 installed

                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
                • P Offline
                  P Offline
                  panoramix
                  wrote on last edited by
                  #9

                  [quote author="SGaist" date="1420068353"]Happy new year to you too !

                  Run ldd on the Qt MySQL plugin to see what libraries it links to. I'd guess that you have something like plugin linked to version 16 of the client library and you have version 18 installed[/quote]

                  Hello.
                  I hope you happily started the new year.

                  I'm using a Linux mint 17.1 and for the moment I want to solve the problem here, then go on to Windows.

                  The version I have on my system is this: ibmysqlclient_r.so.18
                  In fact with ldd is specified that I need 16.

                  @
                  francesco@francesco-M51AC ~/Qt5.4.0/5.4/gcc_64/plugins/sqldrivers $ ldd libqsqlmysql.so
                  linux-vdso.so.1 => (0x00007fff3fdfe000)
                  libmysqlclient_r.so.16 => not found
                  libQt5Sql.so.5 => /home/francesco/Qt5.4.0/5.4/gcc_64/plugins/sqldrivers/./../../lib/libQt5Sql.so.5 (0x00007fd3e387b000)
                  libQt5Core.so.5 => /home/francesco/Qt5.4.0/5.4/gcc_64/plugins/sqldrivers/./../../lib/libQt5Core.so.5 (0x00007fd3e313f000)
                  libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fd3e2e3b000)
                  libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fd3e2a75000)
                  libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fd3e2856000)
                  libicui18n.so.53 => /home/francesco/Qt5.4.0/5.4/gcc_64/plugins/sqldrivers/./../../lib/libicui18n.so.53 (0x00007fd3e240a000)
                  libicuuc.so.53 => /home/francesco/Qt5.4.0/5.4/gcc_64/plugins/sqldrivers/./../../lib/libicuuc.so.53 (0x00007fd3e207f000)
                  libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fd3e1e7a000)
                  libgthread-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgthread-2.0.so.0 (0x00007fd3e1c78000)
                  librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fd3e1a70000)
                  libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007fd3e1767000)
                  libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fd3e1461000)
                  libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fd3e124b000)
                  /lib64/ld-linux-x86-64.so.2 (0x00007fd3e3cf0000)
                  libicudata.so.53 => /home/francesco/Qt5.4.0/5.4/gcc_64/plugins/sqldrivers/./../../lib/libicudata.so.53 (0x00007fd3dfbc2000)
                  libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007fd3df984000)

                  @

                  Because I think the cleanest way to solve it is to recompile the plugin I
                  downloaded the source: qt-everywhere-opensource-src-5.4.0.tar.gz
                  And now my home is organized as below

                  @
                  francesco@francesco-M51AC ~ $ tree -L 1
                  .
                  ├── Documenti
                  ├── Dropbox
                  ├── Immagini
                  ├── Modelli
                  ├── Musica
                  ├── ProgettiQT
                  ├── Pubblici
                  ├── Qt5.4.0
                  ├── qt-everywhere-opensource-src-5.4.0
                  ├── qt-everywhere-opensource-src-5.4.0.tar.gz
                  ├── Scaricati
                  ├── Scrivania
                  └── Video
                  @

                  The plugin should I build is here: ~ / qt-everywhere-opensource-src-5.4.0 / qtbase / src / plugins / sqldrivers

                  @
                  mysql/
                  ├── main.cpp
                  ├── mysql.json
                  ├── mysql.pro
                  └── README
                  @

                  SGaist you can help me to compile it ?
                  I know we are boring and we always ask the same things but I promise that I will do an article on my blog in Italian language and in English so maybe there will be less people asking about it. :-D

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    panoramix
                    wrote on last edited by
                    #10

                    Heureka
                    I managed to solve
                    I go in to the folder containing the source code of the plugin: @~ / qt-everywhere-opensource-src-5.4.0 / qtbase / src / plugins / sqldrivers / mysql@

                    From this folder I launched qmake (not system qmake):
                    @/home/francesco/Qt5.4.0/5.4/gcc_64/bin/./qmake@

                    Then I ran a:
                    @make
                    make install@

                    I had previously removed the original plugin: libqsqlmysql.so (save it somewhere , you never know)

                    Now the new plugin works (Linux mint 17.1) and I can use the demo program sqlbrowser establishing a connection to a MySQL database

                    And this is my new plugin dated 01/01/2015 (I hope this is a good omen for a Happy 2015):-D

                    @francesco@francesco-M51AC ~/Qt5.4.0/5.4/gcc_64/plugins/sqldrivers $ ls -l
                    total 964
                    -rwxr-xr-x 1 francesco francesco 797480 dic 8 22:21 libqsqlite.so
                    -rwxr-xr-x 1 francesco francesco 73328 gen 1 14:20 libqsqlmysql.so
                    -rw-r--r-- 1 francesco francesco 27381 gen 1 14:20 libqsqlmysql.so.tar.gz
                    -rwxr-xr-x 1 francesco francesco 85808 dic 8 22:21 libqsqlpsql.so@

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

                      You shouldn't need to move anything around… Where did you move the plugin folder ?

                      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
                      • P Offline
                        P Offline
                        panoramix
                        wrote on last edited by
                        #12

                        Sorry I was not clear in the explanation.
                        I have not moved the folder of the plugin but I just saved the original library to another folder in the case the new did not work.

                        I also managed to solve the problem on Windows.
                        Simply I used the library for 32-bit architecture, but my application was compiled for 64-bit architecture.
                        The library that I had to use was in the folder: C: \ Program Files \ MySQL \ lib
                        Now everything works on both operating systems: Windows 7, Linux mint 17.1
                        I will try also with Windows 8.1

                        On windows ldd does not exist then for the analysis I used: http://www.dependencywalker.com/

                        If you don't see mistakes in what I did I'll mark the post as solved.

                        Thanks to all

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

                          Nop, everything looks correct you can update the thread title :)

                          Happy coding !

                          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

                          • Login

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