Connecting to MariaDB
-
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"); }
}
-
@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 namedschool
for its database. SQLite ignores anysetHostName()
value because it does not use it.