将数据从MySql插入QT

时间:2018-12-20 18:18:37

标签: c++ mysql qt

我已经将MySql与QT连接了(希望如此),我不知道如何将数据从数据库插入到scrollArea中。我一直在寻找这个问题,但没有找到MySQL的答案。如何将数据从MySql插入到scrollArea?

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
       db.setHostName("localehost");
       db.setDatabaseName("details");
       db.setUserName("root");
       db.setPassword("pass123");
       bool ok = db.open();

}

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

void MainWindow::on_pushButton_2_clicked()
{
    QMessageBox::StandardButton Cancel = QMessageBox::question(this, "Выход", "Выйти?",
                                                               QMessageBox::Yes | QMessageBox::No);
    if (Cancel == QMessageBox::Yes){
        QApplication::quit();
    }else{
        qDebug() << "Button 'Yes' was not clicked";
    }
}

void MainWindow::on_scrollArea_customContextMenuRequested(const QPoint &pos)
{
   //Data from MySQL must be here
}

0 个答案:

没有答案