一、安装qt5
sudo apt-get install qt5-default
sudo apt-get install qtcreator
二、安装MariaDB
sudo apt-get install mariadb-server
允许远程连接
GRANT
ALL
PRIVILEGES
ON
*.*
TO
'root'
@
'%'
IDENTIFIED
BY
'123456'
WITH
GRANT
OPTION
;
flush
privileges
;
修改/etc/mysql/my.cnf文件。打开文件,找到下面内容:
- 1
- 2
- 3
- 1
- 2
- 3
把上面这一行注释掉或者把127.0.0.1换成合适的IP,建议注释掉。
三、安装QT的mysql驱动
很简单
sudo apt-get install libqt5sql5-mysql
四、测试是否安装成功
1、在pro文件中添加 QT += sql
2、
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <QtSql/QSqlDatabase>
#include <QSqlDriver>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
qDebug()<<"Available drivers:";
QStringList drivers=QSqlDatabase::drivers();
foreach(QString dvr,drivers)
{
qDebug()<<dvr;
}
}
MainWindow::~MainWindow()
{
delete ui;
}