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. Accessing Online Database From Qt
Forum Updated to NodeBB v4.3 + New Features

Accessing Online Database From Qt

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 5 Posters 2.1k Views 4 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.
  • carles.sole.grauC Offline
    carles.sole.grauC Offline
    carles.sole.grau
    wrote on last edited by carles.sole.grau
    #1

    Hi everybody,
    I'd like to know if the following code:

    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
        db.setHostName("bigblue");
        db.setDatabaseName("flightdb");
        db.setUserName("acarlson");
        db.setPassword("1uTbSbAs");
        bool ok = db.open();
    

    Is this able to connect to a database located to a server? Or just to connect to a local database (Offline Database)?

    Thanks a lot!

    1 Reply Last reply
    0
    • P Offline
      P Offline
      panosk
      wrote on last edited by
      #2

      Hello,

      That should be enough, as long as the host name is the correct name or IP address of the server and there is no firewall blocking the connection. You may also need to provide the port with db.setPort(int)(the default for MySQL is 3306).

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

        Hi,

        As noted by @panosk, it's enough to connect to a local or remote instance of a MySQL database.

        However, if you plan to connect to a remote server outside of your network, you should reconsider your design. A database should never be accessible directly over internet.

        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
        • carles.sole.grauC Offline
          carles.sole.grauC Offline
          carles.sole.grau
          wrote on last edited by
          #4

          Hi, thank you for your answers,
          I'm trying to connect to a MySQL located in my Hostinger "account".
          Do you know if it has firewall? Because I'm unable to connect.

          Thanks!

          kshegunovK 1 Reply Last reply
          0
          • carles.sole.grauC carles.sole.grau

            Hi, thank you for your answers,
            I'm trying to connect to a MySQL located in my Hostinger "account".
            Do you know if it has firewall? Because I'm unable to connect.

            Thanks!

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by
            #5

            @carles.sole.grau
            There's something more beside the firewalls. Some hosting companies will disable (it's a MySQL server feature) logging into databases from hosts different than the local one, and for a good reason. You should check that as well, even if the port is open and the server is visible you could still fail to connect if that's the case.

            Read and abide by the Qt Code of Conduct

            Joel BodenmannJ 1 Reply Last reply
            0
            • kshegunovK kshegunov

              @carles.sole.grau
              There's something more beside the firewalls. Some hosting companies will disable (it's a MySQL server feature) logging into databases from hosts different than the local one, and for a good reason. You should check that as well, even if the port is open and the server is visible you could still fail to connect if that's the case.

              Joel BodenmannJ Offline
              Joel BodenmannJ Offline
              Joel Bodenmann
              wrote on last edited by
              #6

              You probably want to try to connect to your database using an existing tool before you try it with your own software. This way you are at least sure that the problem is in fact in your software if it doesn't work and not somewhere else (eg. host configuration as mentioned by @kshegunov)

              Industrial process automation software: https://simulton.com
              Embedded Graphics & GUI library: https://ugfx.io

              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