How can I modify software for multi-threading.
I would like to see the minimum basic example in order to figure it out and not get into the wilds for now.
There is a big table (100 thousand names) at their request the GUI hangs. I would like to eliminate it.
The logic was like that.
- The man opens the program.
- The form constructor sent the request to the thread in the database.
- Built framework application.
- We take data from the stream to the main one.
- Fill in the received data table.
ps I tried to do this on signals and slots using QThread. I sent a request to another thread, but it started working only when the main application closes ...
mainwindow.CPP
#include "mainwindow.h" #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 objDatabase; objDatabase = QSqlDatabase::addDatabase("QMYSQL"); objDatabase.setDatabaseName("librarydb"); objDatabase.setHostName("127.0.0.1"); objDatabase.setPort(3306); objDatabase.setUserName("hays0503"); objDatabase.setPassword("hays0503"); objDatabase.open(); //QSqlTableModel *objTableModel; objTableModel = new QSqlTableModel(); objTableModel->setTable("author"); if (!objTableModel->select()) { qDebug()<<"Error"; }else { ui->tableView->setModel(objTableModel); } } mainwindow.H
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QDebug> #include <QSql> #include <QSqlError> #include <QSqlDatabase> #include <QSqlTableModel> namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = nullptr); ~MainWindow(); private slots: void on_pushButton_clicked(); private: Ui::MainWindow *ui; QSqlDatabase objDatabase; QSqlTableModel *objTableModel; }; #endif // MAINWINDOW_H 