Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved QSqlTableModel does not work

    General and Desktop
    3
    3
    132
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • lincoln
      lincoln last edited by lincoln

      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.

      Solitary wolf

      JonB 1 Reply Last reply Reply Quote 0
      • JonB
        JonB @lincoln last edited by

        @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....

        S 1 Reply Last reply Reply Quote 0
        • S
          skoczian @JonB last edited by skoczian

          @JonB Quite right: QTBUG-79033. More of a change in PostgreSQL 12 than a Qt bug, I think, but enough to make QSqlTableModel unusable with PostgreSQL 12 for the time being.

          1 Reply Last reply Reply Quote 1
          • First post
            Last post