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. Cant build QMYSQL driver on Ubuntu 22.04.2 LTS
Forum Updated to NodeBB v4.3 + New Features

Cant build QMYSQL driver on Ubuntu 22.04.2 LTS

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 1.3k 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.
  • S Offline
    S Offline
    SaadAli
    wrote on last edited by
    #1

    I want to connect mysql database with Qt GUI. I dont have QMYSQL drivers installed so I started following the documentation here but can't seem to build it.

    My ubuntu is

    Ubuntu 22.04.2 LTS
    

    I installed Qt creator using

    sudo apt install qtcreator qtbase5-dev
    

    I installed MySql using

    sudo apt install mysql-server
    

    I did could not find the required libmysqlclient.so file on my system so I used the following to get it:

    sudo apt install libmysqlclient-dev
    

    After that I followed the documentation as mentioned above. I had to run (qmake -- MYSQL_PREFIX=/usr/local) in the folder ($QTDIR/qtbase/src/plugins/sqldrivers) as stated in the documentation. I am running the command in (/usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers) directory. When I run the command the output is:

    $ qmake -- MYSQL_PREFIX=/usr/local
    
    Usage: /usr/lib/qt5/bin/qmake [mode] [options] [files]
    
    QMake has two modes, one mode for generating project files based on
    some heuristics, and the other for generating makefiles. Normally you
    shouldn't need to specify a mode, as makefile generation is the default
    mode for qmake, but you may use this to test qmake on an existing project
    
    Mode:
      -project       Put qmake into project file generation mode
                     In this mode qmake interprets [files] as files to
                     be added to the .pro file. By default, all files with
                     known source extensions are added.
                     Note: The created .pro file probably will 
                     need to be edited. For example add the QT variable to 
                     specify what modules are required.
      -makefile      Put qmake into makefile generation mode (default)
                     In this mode qmake interprets files as project files to
                     be processed, if skipped qmake will try to find a project
                     file in your current working directory
    
    Warnings Options:
      -Wnone         Turn off all warnings; specific ones may be re-enabled by
                     later -W options
      -Wall          Turn on all warnings
      -Wparser       Turn on parser warnings
      -Wlogic        Turn on logic warnings (on by default)
      -Wdeprecated   Turn on deprecation warnings (on by default)
    
    Options:
       * You can place any variable assignment in options and it will be *
       * processed as if it was in [files]. These assignments will be    *
       * processed before [files] by default.                            *
      -o file        Write output to file
      -d             Increase debug level
      -t templ       Overrides TEMPLATE as templ
      -tp prefix     Overrides TEMPLATE so that prefix is prefixed into the value
      -help          This help
      -v             Version information
      -early         All subsequent variable assignments will be
                     parsed right before default_pre.prf
      -before        All subsequent variable assignments will be
                     parsed right before [files] (the default)
      -after         All subsequent variable assignments will be
                     parsed after [files]
      -late          All subsequent variable assignments will be
                     parsed right after default_post.prf
      -norecursive   Don't do a recursive search
      -recursive     Do a recursive search
      -set <prop> <value> Set persistent property
      -unset <prop>  Unset persistent property
      -query <prop>  Query persistent property. Show all if <prop> is empty.
      -qtconf file   Use file instead of looking for qt.conf
      -cache file    Use file as cache           [makefile mode only]
      -spec spec     Use spec as QMAKESPEC       [makefile mode only]
      -nocache       Don't use a cache file      [makefile mode only]
      -nodepend      Don't generate dependencies [makefile mode only]
      -nomoc         Don't generate moc targets  [makefile mode only]
      -nopwd         Don't look for files in pwd [project mode only]
    
    

    I have tried running qmake -- MYSQL_PREFIX=/usr/include/mysql aswell but I get the same result.
    I dont have any directory such as $QTDIR/qtbase/src/plugins/sqldrivers ...

    What should I do to build and install the driver for QMYSQL on ubuntu?

    JonBJ 1 Reply Last reply
    0
    • JonBJ JonB

      @SaadAli
      Running qmake is necessary if you are building Qt itself from sources and/or if you need to build the MySQL driver. However when you fetch everything via apt all you need is pre-supplied by Ubuntu. So you don't want to be doing any building/compiling yourself.

      I cannot remember precisely what you have fetch from apt to get all the necessary components (don't forget you can type e.g. apt install libmysql and hit the Tab key twice to see available components). Do not proceed to any qmake steps. After your sudo apt install libmysqlclient-dev where are you in terms of runnability for a minimal program attempting to use QSql... stuff?

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

      @SaadAli

      @JonB said in Cant build QMYSQL driver on Ubuntu 22.04.2 LTS:

      I cannot remember precisely what you have fetch from apt to get all the necessary components

      Try apt install libqt-Tab-Tab. I think you need libqt5sql5-mysql?

      Is there also a need for a libqsqlmysql.so? (Maybe that comes in the above package?)

      S 1 Reply Last reply
      2
      • S SaadAli

        I want to connect mysql database with Qt GUI. I dont have QMYSQL drivers installed so I started following the documentation here but can't seem to build it.

        My ubuntu is

        Ubuntu 22.04.2 LTS
        

        I installed Qt creator using

        sudo apt install qtcreator qtbase5-dev
        

        I installed MySql using

        sudo apt install mysql-server
        

        I did could not find the required libmysqlclient.so file on my system so I used the following to get it:

        sudo apt install libmysqlclient-dev
        

        After that I followed the documentation as mentioned above. I had to run (qmake -- MYSQL_PREFIX=/usr/local) in the folder ($QTDIR/qtbase/src/plugins/sqldrivers) as stated in the documentation. I am running the command in (/usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers) directory. When I run the command the output is:

        $ qmake -- MYSQL_PREFIX=/usr/local
        
        Usage: /usr/lib/qt5/bin/qmake [mode] [options] [files]
        
        QMake has two modes, one mode for generating project files based on
        some heuristics, and the other for generating makefiles. Normally you
        shouldn't need to specify a mode, as makefile generation is the default
        mode for qmake, but you may use this to test qmake on an existing project
        
        Mode:
          -project       Put qmake into project file generation mode
                         In this mode qmake interprets [files] as files to
                         be added to the .pro file. By default, all files with
                         known source extensions are added.
                         Note: The created .pro file probably will 
                         need to be edited. For example add the QT variable to 
                         specify what modules are required.
          -makefile      Put qmake into makefile generation mode (default)
                         In this mode qmake interprets files as project files to
                         be processed, if skipped qmake will try to find a project
                         file in your current working directory
        
        Warnings Options:
          -Wnone         Turn off all warnings; specific ones may be re-enabled by
                         later -W options
          -Wall          Turn on all warnings
          -Wparser       Turn on parser warnings
          -Wlogic        Turn on logic warnings (on by default)
          -Wdeprecated   Turn on deprecation warnings (on by default)
        
        Options:
           * You can place any variable assignment in options and it will be *
           * processed as if it was in [files]. These assignments will be    *
           * processed before [files] by default.                            *
          -o file        Write output to file
          -d             Increase debug level
          -t templ       Overrides TEMPLATE as templ
          -tp prefix     Overrides TEMPLATE so that prefix is prefixed into the value
          -help          This help
          -v             Version information
          -early         All subsequent variable assignments will be
                         parsed right before default_pre.prf
          -before        All subsequent variable assignments will be
                         parsed right before [files] (the default)
          -after         All subsequent variable assignments will be
                         parsed after [files]
          -late          All subsequent variable assignments will be
                         parsed right after default_post.prf
          -norecursive   Don't do a recursive search
          -recursive     Do a recursive search
          -set <prop> <value> Set persistent property
          -unset <prop>  Unset persistent property
          -query <prop>  Query persistent property. Show all if <prop> is empty.
          -qtconf file   Use file instead of looking for qt.conf
          -cache file    Use file as cache           [makefile mode only]
          -spec spec     Use spec as QMAKESPEC       [makefile mode only]
          -nocache       Don't use a cache file      [makefile mode only]
          -nodepend      Don't generate dependencies [makefile mode only]
          -nomoc         Don't generate moc targets  [makefile mode only]
          -nopwd         Don't look for files in pwd [project mode only]
        
        

        I have tried running qmake -- MYSQL_PREFIX=/usr/include/mysql aswell but I get the same result.
        I dont have any directory such as $QTDIR/qtbase/src/plugins/sqldrivers ...

        What should I do to build and install the driver for QMYSQL on ubuntu?

        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by JonB
        #2

        @SaadAli
        Running qmake is necessary if you are building Qt itself from sources and/or if you need to build the MySQL driver. However when you fetch everything via apt all you need is pre-supplied by Ubuntu. So you don't want to be doing any building/compiling yourself.

        I cannot remember precisely what you have fetch from apt to get all the necessary components (don't forget you can type e.g. apt install libmysql and hit the Tab key twice to see available components). Do not proceed to any qmake steps. After your sudo apt install libmysqlclient-dev where are you in terms of runnability for a minimal program attempting to use QSql... stuff?

        S JonBJ 2 Replies Last reply
        0
        • JonBJ JonB

          @SaadAli
          Running qmake is necessary if you are building Qt itself from sources and/or if you need to build the MySQL driver. However when you fetch everything via apt all you need is pre-supplied by Ubuntu. So you don't want to be doing any building/compiling yourself.

          I cannot remember precisely what you have fetch from apt to get all the necessary components (don't forget you can type e.g. apt install libmysql and hit the Tab key twice to see available components). Do not proceed to any qmake steps. After your sudo apt install libmysqlclient-dev where are you in terms of runnability for a minimal program attempting to use QSql... stuff?

          S Offline
          S Offline
          SaadAli
          wrote on last edited by SaadAli
          #3

          @JonB
          I want to highlight according to the best of my knowledge that Qt Creator is normally installed by apt install qt5-default but I used sudo apt install qtcreator qtbase5-dev because Ubuntu 22.04.2 LTS doesn't have qt5-default in its apt repository.

          Pressing Tab after typing apt install libmysql gives me the following options:

          libmysql++3v5        libmysqlcppconn-dev  libmysql-ocaml
          libmysqlclient21     libmysql++-dev       libmysql-ocaml-dev
          libmysqlclient-dev   libmysql-diff-perl   
          libmysqlcppconn7v5   libmysql++-doc
          

          What should I install I have no idea.

          After running sudo apt install libmysqlclient-dev I have achieved nothing. I get the same error when I print QSqlDatabase::lastError().text(). The error is as the following:

          QSqlDatabase: QMYSQL driver not loaded
          QSqlDatabase: available drivers: QSQLITE
          "Driver not loaded Driver not loaded"
          
          1 Reply Last reply
          0
          • JonBJ JonB

            @SaadAli
            Running qmake is necessary if you are building Qt itself from sources and/or if you need to build the MySQL driver. However when you fetch everything via apt all you need is pre-supplied by Ubuntu. So you don't want to be doing any building/compiling yourself.

            I cannot remember precisely what you have fetch from apt to get all the necessary components (don't forget you can type e.g. apt install libmysql and hit the Tab key twice to see available components). Do not proceed to any qmake steps. After your sudo apt install libmysqlclient-dev where are you in terms of runnability for a minimal program attempting to use QSql... stuff?

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

            @SaadAli

            @JonB said in Cant build QMYSQL driver on Ubuntu 22.04.2 LTS:

            I cannot remember precisely what you have fetch from apt to get all the necessary components

            Try apt install libqt-Tab-Tab. I think you need libqt5sql5-mysql?

            Is there also a need for a libqsqlmysql.so? (Maybe that comes in the above package?)

            S 1 Reply Last reply
            2
            • JonBJ JonB

              @SaadAli

              @JonB said in Cant build QMYSQL driver on Ubuntu 22.04.2 LTS:

              I cannot remember precisely what you have fetch from apt to get all the necessary components

              Try apt install libqt-Tab-Tab. I think you need libqt5sql5-mysql?

              Is there also a need for a libqsqlmysql.so? (Maybe that comes in the above package?)

              S Offline
              S Offline
              SaadAli
              wrote on last edited by
              #5

              @JonB
              Installing libqt5sql5-mysql made it work like a charm! Thank you @JonB ! That was all what I was missing.
              But I don't know what is the role of libqsqlmysql.so. I dont know if installing libmysqlclient-dev made any difference. The only thing that happened after installing it was I got the file libqsqlmysql.so on my machine.

              JonBJ 1 Reply Last reply
              0
              • S SaadAli has marked this topic as solved on
              • S SaadAli

                @JonB
                Installing libqt5sql5-mysql made it work like a charm! Thank you @JonB ! That was all what I was missing.
                But I don't know what is the role of libqsqlmysql.so. I dont know if installing libmysqlclient-dev made any difference. The only thing that happened after installing it was I got the file libqsqlmysql.so on my machine.

                JonBJ Online
                JonBJ Online
                JonB
                wrote on last edited by
                #6

                @SaadAli said in Cant build QMYSQL driver on Ubuntu 22.04.2 LTS:

                The only thing that happened after installing it was I got the file libqsqlmysql.so on my machine.

                Yep that's fine, it must be supplied in libqt5sql5-mysql package and that is what is needed.

                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