树莓派raspberry pi安装qt的mysql驱动

来源:互联网 发布:安卓apo源码 编辑:程序博客网 时间:2024/06/11 17:43

一、安装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文件。打开文件,找到下面内容:

 # Instead of skip-networking the default is now to listen only on # localhost which is more compatible and is not less secure. bind-address  = 127.0.0.1
  • 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;
}