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. Difficulties with Getting MySQL to Work with Qt
QtWS25 Last Chance

Difficulties with Getting MySQL to Work with Qt

Scheduled Pinned Locked Moved Solved General and Desktop
mysql driverpluginsmac os x
10 Posts 3 Posters 2.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.
  • ResistorInTheDarkR Offline
    ResistorInTheDarkR Offline
    ResistorInTheDark
    wrote on last edited by ResistorInTheDark
    #1

    Greetings developer gurus,

    I have several questions I would like to ask regarding MySQL for Qt.

    A little bit of context:
    I'm working on a project for school which incorporates a payment system across the school network. Right now, the desktop application that I've written is a standalone and won't be able to communicate over a network.
    I've skimmed briefly through the Qt Network and some examples.
    Initially, I used sqlite but after suggestions from the school ICT and surfing the web for more information, I'm deciding to switch to MySQL.

    I'm working with a Mac but will deploy with Windows (and due to not owning a Windows machine, I have to keep most of my work and initially gui/network testing confined to a Mac).

    Trouble Loading the QMYSQL Plugin
    I have attempted my best at following instructions from Qt, Stack Overflow, etc etc but still haven't been able to successfully load the plugin.
    The installation for MySql went fine and I already have a database called test which is comprised of a single table: students.

    Following instructions from SQL Database Drivers, I cd'ed to the sqldriver directory and tried run qmake -- MYSQL_PREFIX=/usr/local/mysql and got this error:
    Project ERROR: You cannot configure sqldrivers separately within a top-level build.
    The same error appears if I set MYSQL_PREFIX to /usr/local.

    I've tried to do brew reinstall qt --with-mysql-client but not much success from that end either.

    I also checked out BlackStar's pinned post. Unfortunately, it's for Windows only (might be nice to specify that in the thread title).


    I have another question to ask, as an aside:
    Regarding the Client-Server Relationship
    From some of the examples I've seen of using Qt Network, it seems like I'll need to write a server application as well?
    I'm not sure if MySql, by default, provides this or not.

    Any help would be appreciated.

    JonBJ 1 Reply Last reply
    0
    • M Offline
      M Offline
      MrShawn
      wrote on last edited by
      #2

      @SGaist responded to Blackstar's post with:

      "Hi both,

      Like written in the post, these instructions are for Windows. Linux and OS X are far less problematic. On OS X install mysql through e.g. macports with sudo port install mysql56 and on Linux, install the mysql dev packages.

      For the rest just follow Qt's Sql Driver documentation"

      Did you try this?

      ResistorInTheDarkR 1 Reply Last reply
      0
      • M MrShawn

        @SGaist responded to Blackstar's post with:

        "Hi both,

        Like written in the post, these instructions are for Windows. Linux and OS X are far less problematic. On OS X install mysql through e.g. macports with sudo port install mysql56 and on Linux, install the mysql dev packages.

        For the rest just follow Qt's Sql Driver documentation"

        Did you try this?

        ResistorInTheDarkR Offline
        ResistorInTheDarkR Offline
        ResistorInTheDark
        wrote on last edited by
        #3

        @MrShawn thanks for the reply.

        Running sudo port install mysql56 gave me these errors:

        Error: Failed to archivefetch mysql56: version @5.6.34_0: Could not resolve host: ywg.ca.packages.macports.org
        Error: See /opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_databases_mysql56/mysql56/main.log for details.
        Error: Follow https://guide.macports.org/#project.tickets to report a bug.
        Error: Processing of port mysql56 failed
        

        I've followed the instructions on the Qt Sql's Driver documentation several times (see first post).

        I've tried again and tried to run configure -sql-mysql MYSQL_INCDIR=/usr/local/mysql-8.0.12-macos10.13-x86_64/include MYSQL_LIBDIR=/usr/local/mysql-8.0.12-macos10.13-x86_64/lib MYSQL_PREFIX=/usr/local/mysql then make but I get this error:

        make[4]: *** No rule to make target `/Users/user/Applications/Qt/5.11.0/Src/qtbase/include/QtCore/QtConfig', needed by `../../lib/QtCore.framework/Versions/5/Headers/QtConfig'.  Stop.
        make[3]: *** [release-all] Error 2
        make[2]: *** [sub-corelib-make_first] Error 2
        make[1]: *** [sub-src-make_first] Error 2
        make: *** [module-qtbase-make_first] Error 2
        
        1 Reply Last reply
        0
        • M Offline
          M Offline
          MrShawn
          wrote on last edited by
          #4

          I don't use Mac at all so I can't help a lot but have you looked at:
          https://sequelpro.com/docs/ref/mysql/install-on-osx
          There are instruction for installing using macports.
          "This method works only if you have MacPorts and the XCode Developer Tools installed"
          Maybe the mysql56 is an old version or you don'r have macports installed since it cant resolve host?

          1 Reply Last reply
          2
          • ResistorInTheDarkR ResistorInTheDark

            Greetings developer gurus,

            I have several questions I would like to ask regarding MySQL for Qt.

            A little bit of context:
            I'm working on a project for school which incorporates a payment system across the school network. Right now, the desktop application that I've written is a standalone and won't be able to communicate over a network.
            I've skimmed briefly through the Qt Network and some examples.
            Initially, I used sqlite but after suggestions from the school ICT and surfing the web for more information, I'm deciding to switch to MySQL.

            I'm working with a Mac but will deploy with Windows (and due to not owning a Windows machine, I have to keep most of my work and initially gui/network testing confined to a Mac).

            Trouble Loading the QMYSQL Plugin
            I have attempted my best at following instructions from Qt, Stack Overflow, etc etc but still haven't been able to successfully load the plugin.
            The installation for MySql went fine and I already have a database called test which is comprised of a single table: students.

            Following instructions from SQL Database Drivers, I cd'ed to the sqldriver directory and tried run qmake -- MYSQL_PREFIX=/usr/local/mysql and got this error:
            Project ERROR: You cannot configure sqldrivers separately within a top-level build.
            The same error appears if I set MYSQL_PREFIX to /usr/local.

            I've tried to do brew reinstall qt --with-mysql-client but not much success from that end either.

            I also checked out BlackStar's pinned post. Unfortunately, it's for Windows only (might be nice to specify that in the thread title).


            I have another question to ask, as an aside:
            Regarding the Client-Server Relationship
            From some of the examples I've seen of using Qt Network, it seems like I'll need to write a server application as well?
            I'm not sure if MySql, by default, provides this or not.

            Any help would be appreciated.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #5

            @ResistorInTheDark said in Difficulties with Getting MySQL to Work with Qt:

            While you await a solution to your main installation issue:

            I have another question to ask, as an aside:
            Regarding the Client-Server Relationship
            From some of the examples I've seen of using Qt Network, it seems like I'll need to write a server application as well?
            I'm not sure if MySql, by default, provides this or not.

            MySQL (well, the MySQL server daemon on the server) acts as a "server application". You will not have write some server-side application/code yourself. While you develop you will run the MySQL server on your standalone workstation and your Qt client application will connect to it, when you "go live" the MySQL server will be on a network machine but all you will have to do is change to the correct connection string and your Qt MySQL client code will chat with the server automatically without your code knowing about it.

            ResistorInTheDarkR 1 Reply Last reply
            1
            • ResistorInTheDarkR Offline
              ResistorInTheDarkR Offline
              ResistorInTheDark
              wrote on last edited by ResistorInTheDark
              #6

              @MrShawn

              Thanks for your reply. Running sudo port install mysql5-server gave this error:

              Error: Failed to checksum mysql5: mysql-5.1.72.tar.gz does not exist in /opt/local/var/macports/distfiles/mysql51
              

              Well, the good news is that I fiddled some more with my code and eventually it was able to run. :-) I think it might've been because I was trying to initialise .db files (for sqlite). Not sure how the plugin worked out. I thought that it wasn't loaded at all (apparently, seems like it was already loaded).

              Well, problem solved (for now). Thanks again for your help!

              1 Reply Last reply
              0
              • JonBJ JonB

                @ResistorInTheDark said in Difficulties with Getting MySQL to Work with Qt:

                While you await a solution to your main installation issue:

                I have another question to ask, as an aside:
                Regarding the Client-Server Relationship
                From some of the examples I've seen of using Qt Network, it seems like I'll need to write a server application as well?
                I'm not sure if MySql, by default, provides this or not.

                MySQL (well, the MySQL server daemon on the server) acts as a "server application". You will not have write some server-side application/code yourself. While you develop you will run the MySQL server on your standalone workstation and your Qt client application will connect to it, when you "go live" the MySQL server will be on a network machine but all you will have to do is change to the correct connection string and your Qt MySQL client code will chat with the server automatically without your code knowing about it.

                ResistorInTheDarkR Offline
                ResistorInTheDarkR Offline
                ResistorInTheDark
                wrote on last edited by
                #7

                @JonB

                Thanks for your reply. That's somewhat of a relief to me.

                but all you will have to do is change to the correct connection string

                Is it possible to elaborate more on connection string? Would that be like smb://192.168.1.4 instead of localhost?

                If say, I borrow my sibling's laptop and deploy my application there. And let's say that I have a mysql server active on my computer. My computer and my sibling's laptop are in the same network. Would the "connection string" depend on the ip address of my computer (where the sql server is)?

                JonBJ 1 Reply Last reply
                0
                • ResistorInTheDarkR ResistorInTheDark

                  @JonB

                  Thanks for your reply. That's somewhat of a relief to me.

                  but all you will have to do is change to the correct connection string

                  Is it possible to elaborate more on connection string? Would that be like smb://192.168.1.4 instead of localhost?

                  If say, I borrow my sibling's laptop and deploy my application there. And let's say that I have a mysql server active on my computer. My computer and my sibling's laptop are in the same network. Would the "connection string" depend on the ip address of my computer (where the sql server is)?

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #8

                  @ResistorInTheDark
                  Bear in mind I know nothing about Macs. Yes, by "connection string" I was referring to whatever MySQL takes to address the server.

                  Your own machine is always available as localhost. Or IP address 127.0.0.1. Additionally you'll have an IP address local to your network, 192.168.x.y. And the other machine on the network will have a 192.168.p.q. Your Mac network may also allow to address the other machine by a name.

                  You'll pass one of those two to your client MySQL connection. (Whether it will start with your smb: I don't know.) You may have to set the MySQL server to allow connections to come in from other machines on the network in addition to localhost, especially when you "go live" on the real network.

                  1 Reply Last reply
                  3
                  • M Offline
                    M Offline
                    MrShawn
                    wrote on last edited by
                    #9

                    I am glad it seems to be working now.

                    Addressing the second portion of your post:
                    It is hard to say because I do not know enough of what exactly you are trying to do. Let me explain - if your payment system means to simply update/insert data in the DB then you do not need to have a server application. The MySQL server instance in this case will act like @JonB said as your server application where the data for the clients are centralized and can be accessed independently of one another. If on the other hand you require much more complicated functionality, (i.e. confirming payments or just in general a process that the data has to go through) where it is not appropriate to manage the data in the client application then you might want to consider a server application. If you take a server application approach you probably do not need MySQL drivers for the client app, because the backend communication will be done via the server not the client.

                    My advice is to keep it as simple as you can. If your project needs to be a simple insert/update then do not consider a server application at all. Also I would consider setting up a remote DB instead of using local host for your DB instance because there will be real differences on performance when querying the DB over the network rather than no network at all. I learned this the hard way. Granted you are likely not doing a lot of queries at a high frequency you still want to get all the obstacles you can in the open so you can plan your solutions accordingly.

                    1 Reply Last reply
                    2
                    • ResistorInTheDarkR Offline
                      ResistorInTheDarkR Offline
                      ResistorInTheDark
                      wrote on last edited by
                      #10

                      @JonB @MrShawn

                      Thanks you two for clarifying.

                      After downloading/installing a MySQL server in a school computer, I could build/run my app on my computer and insert/update data successfully to the server. That part's all good. Thanks from y'all.

                      Marking as solved.

                      1 Reply Last reply
                      2

                      • Login

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