QSqlTableModel does not work
-
How about friends, I have the following problem.
I have a QTableView and I want to set a model through QSqlTableModel, but when I do nothing appears in the tableview, this happens to me with version 12 of postgresql, but when I change to version 11, everything goes well, someone knows why it doesn't work with one version and the other if.
#include "dialog.h" #include "ui_dialog.h" #include <QSqlDatabase> #include <qsqlerror.h> #include <QSqlTableModel> #include <QMessageBox> Dialog::Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog) { ui->setupUi(this); QSqlDatabase db=QSqlDatabase::addDatabase("QPSQL"); if(!db.isDriverAvailable("QPSQL")) { QMessageBox::critical(nullptr,qApp->applicationName(), "Error al cargar el controlador.\n"+ db.lastError().text()); return; } db.setPort(5433); db.setHostName("127.0.0.1"); db.setDatabaseName("ejemplo"); db.setUserName("postgres"); db.setPassword("12345678"); if(!db.open()) { QMessageBox::critical(nullptr,qApp->applicationName(), "Error al abrir la base de datos.\n"+ db.lastError().text()); return; } QSqlTableModel *model=new QSqlTableModel(this); model->setTable("usuario"); model->select(); ui->tableView->setModel(model); } Dialog::~Dialog() { delete ui; }
I already added the necessary libraries to make it work, I mean:
libeay32.dll, libiconv-2.dll, libintl-8.dll, libpq.dll, ssleay32.dll
as I said it works perfectly with version 11, but with 12 no, any suggestions, thanks.
-
@lincoln
I think that recently there was a thread in this forum, stating that because of a bug some version of Qt does not work with some version of postgresql, and I think it was around the version numbers you will be using.Search this forum for
postgresql
, and I think you will find it, it's within the last month I believe....