Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSqlTableModel does not work
Qt 6.11 is out! See what's new in the release blog

QSqlTableModel does not work

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 631 Views
  • 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.
  • lincolnL Offline
    lincolnL Offline
    lincoln
    wrote on last edited by lincoln
    #1

    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

    JonBJ 1 Reply Last reply
    0
    • lincolnL 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.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @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
      0
      • JonBJ JonB

        @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 Offline
        S Offline
        skoczian
        wrote on last edited by skoczian
        #3

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

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved