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. Connecting to MariaDB
Forum Updated to NodeBB v4.3 + New Features

Connecting to MariaDB

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 1.6k Views 2 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.
  • SGSDoomS Offline
    SGSDoomS Offline
    SGSDoom
    wrote on last edited by
    #1

    I am going through tutorials etc. starting to learn Qt C++. I have created a test DB using MariaDb that is running on a Raspberry PI.

    I setup the connection as per Documentation and it says its connected even if I remove the last octet off the IP address

    How can this be? Any help would be gratefully received. And Happy Holidays to everyone.

    #include "ui_mainwindow.h"

    MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    void MainWindow::on_pushButton_clicked()
    {
    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setHostName("192.168.1.");
    db.setUserName("root");
    db.setPassword("rootpassword");
    db.setDatabaseName("school");

    if(db.open()) {
    
        QMessageBox::information(this, "Connection", "Database Connected Successfully");
    
    } else {
        QMessageBox::information(this, "Not Connected", "Database is not Connected");
    
    }
    

    }

    JonBJ 1 Reply Last reply
    0
    • SGSDoomS Offline
      SGSDoomS Offline
      SGSDoom
      wrote on last edited by
      #7

      @mrdebug changing to QMysql worked. Thank you for that. Happy Holidays.

      1 Reply Last reply
      0
      • SGSDoomS SGSDoom

        I am going through tutorials etc. starting to learn Qt C++. I have created a test DB using MariaDb that is running on a Raspberry PI.

        I setup the connection as per Documentation and it says its connected even if I remove the last octet off the IP address

        How can this be? Any help would be gratefully received. And Happy Holidays to everyone.

        #include "ui_mainwindow.h"

        MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
        {
        ui->setupUi(this);
        }

        MainWindow::~MainWindow()
        {
        delete ui;
        }

        void MainWindow::on_pushButton_clicked()
        {
        QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
        db.setHostName("192.168.1.");
        db.setUserName("root");
        db.setPassword("rootpassword");
        db.setDatabaseName("school");

        if(db.open()) {
        
            QMessageBox::information(this, "Connection", "Database Connected Successfully");
        
        } else {
            QMessageBox::information(this, "Not Connected", "Database is not Connected");
        
        }
        

        }

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

        @SGSDoom said in Connecting to MariaDB:

        and it says its connected even if I remove the last octet off the IP address

        Because at a guess it defaults to 0, and your IP address is 192.168.1.0?

        1 Reply Last reply
        0
        • SGSDoomS Offline
          SGSDoomS Offline
          SGSDoom
          wrote on last edited by
          #3

          no sorry last octet is actually 193

          JonBJ 1 Reply Last reply
          0
          • SGSDoomS SGSDoom

            no sorry last octet is actually 193

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

            @SGSDoom
            Then I don't know how it manages to pick the right machine. Maybe because it's Christmas? :)

            EDIT
            Hang on, wait!

            I have created a test DB using MariaDb that is running on a Raspberry PI.

            Nope, because you have QSqlDatabase::addDatabase("QSQLITE");. You are not connecting to your MariaDB, you are using SQLite to connect to a physical, local file! If you look around your disk (probably whatever the current directory is when you ran your code) you should find it has created a file named school for its database. SQLite ignores any setHostName() value because it does not use it.

            1 Reply Last reply
            2
            • mrdebugM Offline
              mrdebugM Offline
              mrdebug
              wrote on last edited by
              #5

              Maybe because you have chosen QSQLITE and QSQLITE driver type don't require a tcp connection. Please try mysql driver type.

              Need programmers to hire?
              www.labcsp.com
              www.denisgottardello.it
              GMT+1
              Skype: mrdebug

              1 Reply Last reply
              2
              • SGSDoomS Offline
                SGSDoomS Offline
                SGSDoom
                wrote on last edited by
                #6

                ok, back to the old forum posts of building the driver as not loaded.

                1 Reply Last reply
                0
                • SGSDoomS Offline
                  SGSDoomS Offline
                  SGSDoom
                  wrote on last edited by
                  #7

                  @mrdebug changing to QMysql worked. Thank you for that. Happy Holidays.

                  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