Navigation

    Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Search
    • Unsolved
    1. Home
    2. Tags
    3. qsqltablemodel
    Log in to post

    • UNSOLVED TableView not updated or refreshed unless column is resized and scroll bar move up and down few times
      General and Desktop • qsqltablemodel proxy model sort filter • • VikramSamy  

      5
      0
      Votes
      5
      Posts
      76
      Views

      @JonB said in TableView not updated or refreshed unless column is resized and scroll bar move up and down few times: @VikramSamy I'm not sure where exactly you are saying your issue is. Be aware that when you insert new rows the model emits rowsInserted() signal, not dataChanged(). Not that it should matter, as the table view listens for either and updates accordingly. If you think it might be a proxy model issue, QT has QIdentityProxyModel. This is a "null" proxy, it does nothing other than pass everything through to/from the source model. Try that instead of your QSortFilterProxyModel, if that works you have some issue in the QSFPM. I meant the codes work fine after I just delete the sql database Table, and created a new table with empty records. so now when the data is inserted in to the SQLtable model, both the database and the View is updated accordingly, anyway im not sure also why, but currently the record/row count about 100++ records only, I just guess after insertions of many record reaching 1000++ then the behavior will change as describe is my 1st post...anyhow il just test and study again and update here with more clearer picture of my issue.
    • UNSOLVED QSqlError("1045", "QMYSQ") Cannot edit table with QSqlTableModel
      General and Desktop • mysql qsqltablemodel qsqlerror linux desktop error 1045 • • Shellcpp73  

      9
      0
      Votes
      9
      Posts
      173
      Views

      It's or sure no problem of Qt or the QSqlTableModel - fix your access rights.
    • UNSOLVED UNIQUE CONSTRAINT FAILED on submitAll()
      General and Desktop • qsqltablemodel sqlite3 qsql qsqlrelationalt unique • • dave997  

      1
      0
      Votes
      1
      Posts
      81
      Views

      No one has replied

    • SOLVED QSqlTableModel removeRow() not removing records from some tables ?
      General and Desktop • database sqlite qsqltablemodel qsqlite • • R-P-H  

      5
      0
      Votes
      5
      Posts
      158
      Views

      The QSqlTableModel needs a real PK, yes.
    • UNSOLVED Problem using QSqlTableModel with several sqlite databases
      General and Desktop • qsqltablemodel • • adabreug94  

      2
      0
      Votes
      2
      Posts
      93
      Views

      @adabreug94 said in Problem using QSqlTableModel with several sqlite databases: Following Qt documentation recommendations, I have placed the brackets to being able of safe closing and deleting the database connection after finish using it. But you did not finish using it - the QSqlQueryModel still has an instance on it. I would suggest simply using different connection names for the different connections.
    • UNSOLVED Unable to edit QSqlTableModel from QML
      QML and Qt Quick • model sqlite model-view qsqltablemodel • • daljit97  

      4
      0
      Votes
      4
      Posts
      287
      Views

      @daljit97 said in Unable to edit QSqlTableModel from QML: , Qt::EditRole); Then you should probably pass the role and not editRole, otherwise model won't know which column to update.
    • SOLVED QSqlTableModel() empty on Ubuntu but works on Windows ?
      General and Desktop • qsqltablemodel qsqldatabase postgresql • • R-P-H  

      41
      0
      Votes
      41
      Posts
      2197
      Views

      Upgrading to Qt Version 5.15+ solved the issue.
    • UNSOLVED converting from mySQL to SQlite with QSqlTableModel
      General and Desktop • mysql pyqt5 sqlite qsqltablemodel • • Johnny78  

      7
      0
      Votes
      7
      Posts
      451
      Views

      I did the migration with mysqldump then I edited the dump file. Then I have the resulting file into sqlite and saved it as database. The date columns are now stored in sqlite as TEXT fields. All done on a linux machine. Thank you VRonin for your suggestion. That sounds like a great idea. Can I do this in pyQt5 or do I need to go to C++? I think QSQLiteDriver is a plugin i.e. a shared library. That means I have to do this in C++. Is that right? I wanted to avoid C++ so that my application is more portable. But anyway this solution sounds great. Thanks for you answers guys.
    • SOLVED Saving memory by freeing off-screen QListView items?
      General and Desktop • listview sql model qlistview qsqltablemodel • • tague  

      10
      0
      Votes
      10
      Posts
      475
      Views

      @Christian-Ehrlicher It caches entries that could have fairly high resolution images in them. 100MB consumed is quite reasonable for my particular use case. I've solved my problem my creating a general-purpose list model class which does not retain too many recent items in memory, and then implementing an application-specific subclass that will automatically produce small, low-resolution thumbnails and save them to a separate table to allow for faster loading later on.
    • UNSOLVED How to edit cell row in costume model which inherits from QSqlTableModel ?
      QML and Qt Quick • qml model-view qsqltablemodel • • Ahti  

      2
      0
      Votes
      2
      Posts
      168
      Views

      @Ahti Dunno, but why don't you start by showing us/yourself the return values of the calls to user_model.setData(user_model.index(...? What's the result for you of: https://doc.qt.io/qt-5/qsqltablemodel.html#editStrategy ?
    • SOLVED QSqlRelationalTableModel won't save row edits when relation is set
      General and Desktop • qsqltablemodel sqlite3 • • eleventy  

      6
      0
      Votes
      6
      Posts
      391
      Views

      @eleventy Ah ha! I did think it would be a good idea to go back to some simple example Qt provides, because one can be unaware that a change one has made can affect things unexpectedly! Sounds like you now have what you were supposed to have, well done!
    • UNSOLVED QTableView Empty ?
      General and Desktop • qtableview qsqltablemodel sqlite3 • • R-P-H  

      18
      0
      Votes
      18
      Posts
      1731
      Views

      Yes you do, or you can make your own custom QAbstractTableModel that will return the content of your vector of records. Yes you do. However you can use an in-memory database if you don't want to have another database in a file.
    • UNSOLVED How to filter out columns in the new Quick Controls 2.12 TableView?
      QML and Qt Quick • tableview qsqltablemodel quick controls models qml components • • ivarec  

      1
      0
      Votes
      1
      Posts
      285
      Views

      No one has replied

    • SOLVED How to share database connection parameters between multiple QSqlTableModel objects?
      QML and Qt Quick • database qsqltablemodel qsqldatabase models model binding • • ivarec  

      6
      0
      Votes
      6
      Posts
      875
      Views

      From the looks of it, you have to re-create the models when you change these settings.
    • SOLVED QSqlRelationalDelegate's default value
      General and Desktop • qt5 qtableview qsqltablemodel qsqlrelational • • Kot Shrodingera  

      6
      0
      Votes
      6
      Posts
      890
      Views

      So my final solution is: class SqlRelationalDelegate : public QSqlRelationalDelegate { Q_OBJECT public: StorageSqlRelationalDelegate(QObject* parent = nullptr) : QSqlRelationalDelegate(parent) {} QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const override { editor = QSqlRelationalDelegate::createEditor(parent, option, index); return editor; } void destroyEditor(QWidget* editor, const QModelIndex& index) const override { QSqlRelationalDelegate::destroyEditor(editor, index); this->editor = nullptr; } QWidget* getEditor() const { return editor; } private: mutable QWidget* editor = nullptr; }; ... class TableView : public QTableView { Q_OBJECT public: StorageTableView(QWidget* parent = nullptr) {} void openPersistentEditor(const QModelIndex &index) { QTableView::openPersistentEditor(index); emit persistentEditorOpened(index); } signals: void persistentEditorOpened(const QModelIndex &index); }; ... connect(view, &TableView::persistentEditorOpened, [view] (const QModelIndex& index) { auto model = view->model(); auto delegate = qobject_cast<SqlRelationalDelegate*>(view->itemDelegate(index)); if (!delegate) qFatal("Delegate cast error"); delegate->setModelData(delegate->getEditor(), model, index); });
    • SOLVED QSqlTableModel signal on insert row submit
      General and Desktop • qt5 qsqltablemodel qsqlrelational • • Kot Shrodingera  

      9
      0
      Votes
      9
      Posts
      1525
      Views

      @VRonin Ah. I believe the user described the interface he gets currently (with his QTableView). Whether he likes it or not is a different matter. Then his question was: how does he get a notification when, having created a new row, it is actually sent to the database for INSERT, given that there is no signal for this in his case ("editStrategy is OnFieldChange"). My overriding QSqlTableModel::insertRowIntoTable() is how to achieve that. So yours is to do with the interface for adding a new row, right? Whether he would benefit/prefer to change over to that to I cannot say :)
    • UNSOLVED Conversion of a SQL model into a standard item model?
      General and Desktop • qsqltablemodel qstandarditemmo data models software design proxies • • elfring  

      35
      0
      Votes
      35
      Posts
      3668
      Views

      I don't understand this question. How do you think about information from Cppcheck's forum and issue tracker? Do you care for software aspects which can be discussed there?
    • UNSOLVED Software development challenges around setHorizontalHeaderLabels()
      General and Desktop • qsqltablemodel qstandarditemmo software design labels databases • • elfring  

      9
      0
      Votes
      9
      Posts
      1046
      Views

      What further software evolution ? You might occasionally find SQL data models more promising, don't you?
    • UNSOLVED Problem inserting record into QSqlTableModel of Postgresql
      General and Desktop • qsqltablemodel postgresql new record • • Bambang_P  

      16
      1
      Votes
      16
      Posts
      3673
      Views

      To use it as a model for QTableView with PostgreSQL 9.1 on PySide2, I subclass QSqlTableModel and rewrite the function insertRowIntoTable (assuming the primary key of serial type is the first field of the record) : def insertRowIntoTable(self, values): if QSqlTableModel.insertRowIntoTable(self, values): # returns the value of the primary key "autovalue" (serial) only when the record is added in database rs = QSqlQuery() rs.exec_("SELECT CURRVAL (pg_get_serial_sequence('public." + self.tableName() + "','"+ self.primaryKey().field(0).name() +"'))") if rs.next(): ID = rs.value(0) # without this line the row displayed in the QTableView immediately after insertion cannot be updated self.setData (self.index(self.rowCount()-1,0), ID) # without this line the created row appears blank in the QTableView values.remove(0) return True return False
    • SOLVED Unable to read data from QSqlTableModel in Qml : "role names" are not defined
      General and Desktop • qml sql sqlite qsqltablemodel c++ to qml • • daljit97  

      11
      0
      Votes
      11
      Posts
      2017
      Views

      @SGaist Ok that makes sense. Thank you
    • UNSOLVED sqlite commands not working in qt
      General and Desktop • qtcreator qsqltablemodel sqlite view • • Calvin Richerd  

      3
      0
      Votes
      3
      Posts
      1327
      Views

      @mranger90 said in sqlite commands not working in qt: Apparently you can not directly access an SQLite database from a resource. There are some discussions about this, but I cant find the links right now. Indeed, Qt resources are compiled into the executable (or standalone binary file) which is read-only. Good catch! :-)
    • SOLVED Update combobox data from model
      General and Desktop • qcombobox qsqltablemodel • • rudag  

      8
      0
      Votes
      8
      Posts
      3211
      Views

      I did this: ui->comboBox->clear(); ((QSqlTableModel*)ui->comboBox->model())->select(); And it's working!
    • SOLVED Selecting a database while using QSqlTableModel
      General and Desktop • sql database qsqltablemodel • • spektro37  

      8
      0
      Votes
      8
      Posts
      2918
      Views

      @spektro37 Well its used with all QWidgets so would make sense. Its something to be aware of when creating GUI and also the little note that any QWidget that are not given a owner/parent, will become a window. That can be surprised when coming from other frameworks. Say you make a new label QLabel *lab= new QLabel(); Since its given no parent, it will become a window. That was pretty surprising to me first time as i wanted to insert it into the main window. So its good to know about.
    • UNSOLVED QSqlTableModel only fetching table headers (with names) and no data from table QODBC
      General and Desktop • qtableview sql qsqltablemodel odbc netezza • • michalos  

      17
      0
      Votes
      17
      Posts
      8755
      Views

      I've uncovered the same issue with QSqlQueryModel using the Windows QODBC database engine connected to MS SQL Server, and have been do some digging. Hopefully this will help others experiencing this issue. There are a couple of different things happening here. First, QSqlQueryModel does not support forward only queries. If you try to use a forward only query, QSqlQueryModel::lastError() will return "Forward-only queries cannot be used in a data model". That seems clear, but does not explain the situation when the forward only is left in its default false state or explicitly set in code. During my exploration of the issue, I would notice that even though I called QSqlQuery::setForwardOnly(false), a call to QSqlQuery::isForwardOnly() made after the query was executed would show forward only set to true, something I did not understand. Then I read the Qt documentation for setForwardOnly: Setting forward only to false is a suggestion to the database engine, which has the final say on whether a result set is forward only or scrollable. isForwardOnly() will always return the correct status of the result set. The database engine has the final say whether or not forward only is used! Why was the database engine setting forward only? Qt's SQL Database Drivers documentation gives part of the answer if you know what you are looking at. ODBC Stored Procedure Support With Microsoft SQL Server the result set returned by a stored procedure that uses the return statement, or returns multiple result sets, will be accessible only if you set the query's forward only mode to forward using QSqlQuery::setForwardOnly(). By observation, the QODBC database engine (in Qt 5.8) recognizes when more than one return set has resulted from the query, so it is automatically setting forward only to true. How are multiple result sets generated? I've uncovered a few ways. A query that has multiple select statements (e.g. select * from table1; select * from table2). Stored Procedures In particular, MS SQL Server documentation has this to say: SQL Server stored procedures have four mechanisms used to return data: Each SELECT statement in the procedure generates a result set. The procedure can return data through output parameters. A cursor output parameter can pass back a Transact-SQL server cursor. The procedure can have an integer return code. The first item in Microsoft's list was the key for me. When NOCOUNT is OFF, Even a simple internal variable assignment using a select (e.g. select @user = 'fred') generated a return set. Setting NOCOUNT to ON stops this behavior. From Microsoft's documentation on NOCOUNT SET NOCOUNT ON prevents the sending of DONE_IN_PROC messages to the client for each statement in a stored procedure. For stored procedures that contain several statements that do not return much actual data, or for procedures that contain Transact-SQL loops, setting SET NOCOUNT to ON can provide a significant performance boost, because network traffic is greatly reduced. The Solution for me turned out to be two things: Add SET NOCOUNT ON to the top of my stored procedure so that only the select statement I cared about was returned Instead of using QSqlQueryModel, manually extract the results from the query and build my own QStandardItemModel.
    • SOLVED Adding columns to a proxy model without affecting the source model
      General and Desktop • qsqltablemodel proxy • • mjsurette  

      3
      0
      Votes
      3
      Posts
      1389
      Views

      Awesome! Thank you @VRonin .
    • UNSOLVED QSqlTableModel problem with set data
      General and Desktop • qsqltablemodel qsqlite • • Xardas  

      4
      0
      Votes
      4
      Posts
      1622
      Views

      Either trigger the submit yourself or fill all fields in the row.
    • SOLVED QSqlRelationalTableModel get relation foreign key value
      General and Desktop • qsqltablemodel qsql qsqlrelation • • maurosanjo  

      8
      1
      Votes
      8
      Posts
      4816
      Views

      @maurosanjo Well, I'm all out of ideas, sorry.
    • SOLVED QSqlTableModel with SQLITE and MySQL
      General and Desktop • sql qsqltablemodel • • hrompato  

      6
      0
      Votes
      6
      Posts
      2541
      Views

      That might happen ;) By the way, no need to modify the title anymore. You can use the topic tool button to mark the thread as solved :)
    • SOLVED Choosing columns for display in an QSqlTableModel
      General and Desktop • qsqltablemodel • • gabor53  

      20
      0
      Votes
      20
      Posts
      8541
      Views

      @SGaist Thank you. I was missing a }.
    • UNSOLVED QSqlRelationalTableModel::removeRow causes relation delegate to dissapear before select()
      General and Desktop • qtableview qsqltablemodel qsqlrelation • • dijuna  

      1
      0
      Votes
      1
      Posts
      546
      Views

      No one has replied

    • UNSOLVED Help a newbie to deal with QTreeView & Model
      General and Desktop • qtreeview qsqltablemodel • • Sasha.S  

      2
      0
      Votes
      2
      Posts
      972
      Views

      I don't know if there are any Qt models that support SQL for trees. I think they were all built for tables so you might have to build one yourself. Have you checked out the Simple Tree Model example? I found it pretty helpful: http://doc.qt.io/qt-5/qtwidgets-itemviews-simpletreemodel-example.html . Also, if you find it easier, you can use a QStandardItemModel instead of a QAbstractItemModel.
    • UNSOLVED SqlModels: QSqlTableModel's that are created entirely from QML
      Showcase • qml sql model thread qsqltablemodel • • Leei  

      13
      0
      Votes
      13
      Posts
      4278
      Views

      @SGaist I don't mind refactoring it, it's not very long. I will definitely look into this. Thanks!
    • SOLVED Extend QSqlTableModel & Update model data;
      General and Desktop • qsqltablemodel qproxymodel • • ginkgoguy  

      14
      0
      Votes
      14
      Posts
      5965
      Views

      An example of myModel->setData(myCustomValue, Qt::UserRole + 1); ?
    • UNSOLVED Remove row from QSqlTableModel
      General and Desktop • qsqltablemodel delete row • • sachi  

      7
      0
      Votes
      7
      Posts
      2602
      Views

      Sorry for the late reply. Hidden row is not working because i want to remove row when user click over that row. I did is using TableView's on_table_clicked slot. if i hidden row from model tableView's index and model's index are not going to match. Is there any other solution?
    • UNSOLVED How can I assign the click event handler as I click the row in QT?
      General and Desktop • qtableview qsqltablemodel qtsql • • gapry  

      2
      0
      Votes
      2
      Posts
      965
      Views

      Hi and welcome to devnet, You can use the doubleClicked signal for that.
    • UNSOLVED Update QSqlTableModel after QSqlQuery executing
      General and Desktop • qsqltablemodel qsqldatabase qsqlquery filtering • • EskeHagen  

      4
      0
      Votes
      4
      Posts
      2524
      Views

      Adapted from the documentation example: model->setFilter("should_alarm=1");
    • UNSOLVED QSqlTableModel - setting default values using the primeInsert signal.
      General and Desktop • qt5.5 qsqltablemodel • • mawh1960  

      1
      0
      Votes
      1
      Posts
      655
      Views

      No one has replied

    • QSqlTableModel performance problem
      General and Desktop • qwidget qtableview qsqltablemodel performance • • looping  

      3
      0
      Votes
      3
      Posts
      908
      Views

      @QtTester said in QSqlTableModel performance problem: tablemodel->setData is unacceptable, query.bindData is much faster than model.setData() But they're two completely different things...
    • [SOLVED]Represent data as combo box or checkbox
      General and Desktop • qtableview qsqltablemodel custom delegate • • sachi  

      5
      0
      Votes
      5
      Posts
      1503
      Views

      Thank you for your help. I have subclass the QSortFilterProxyModel and set flags returns Qt::ItemIsUserCheckble. it worked well