Answer the question
In order to leave comments, you need to log in
How to display ACCESS table in QTablView?
I just started to master cpp and QT, and there was a need for information from the access database to appear in the tableView.
However, the debugger complains and issues:
"QSqlDatabase: an instance of QCoreApplication is required for loading driver plugins
Error in opening
16:27:57: C:\Users\user1\Desktop\QT\projects\build-QVIZ-Desktop_Qt_6_1_0_MinGW_64_bit-Release\release \QVIZ.exe exited with code 0"
I can't figure out what to do about it.
Most likely there is an error somewhere in the code, but apparently there is not enough experience to understand where.
Here is the code in main.cpp
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName("Driver={Microsoft Access Driver (*.mdb, *.accdb)}; DNS=''; resultsDB.accdb");
if (db.open())
qDebug() << "good";
else
{
qDebug() << "bad";
return -0;
}
QTableView view;
QSqlTableModel model;
model.setTable("resultsDB");
model.select();
view.setModel(&model);
view.show();
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
setWindowTitle("placeholdername");
setWindowIcon(QIcon(":/img/img/Icon.png"));
setCentralWidget(ui->stackedWidget);
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName("Driver={Microsoft Access Driver (*.mdb, *.accdb)}; DNS=''; resultsDB.accdb");
if (db.open())
qDebug() << "good";
else
{
qDebug() << "bad";
return -0;
}
QSqlTableModel model;
model.setTable("resultsDB");
model.select();
ui->tableView->setModel(&model);
};
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question