Navigation

    Qt Forum

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

    • UNSOLVED Problem using QSqlTableModel with several sqlite databases
      General and Desktop • qsqltablemodel • • adabreug94  

      2
      0
      Votes
      2
      Posts
      21
      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 • sqlite model model-view qsqltablemodel • • daljit97  

      4
      0
      Votes
      4
      Posts
      58
      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
      303
      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
      113
      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
      151
      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
      44
      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
      127
      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
      816
      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
      158
      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
      571
      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
      697
      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
      1176
      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
      2278
      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 databases labels • • elfring  

      9
      0
      Votes
      9
      Posts
      648
      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  

      14
      1
      Votes
      14
      Posts
      2591
      Views

      @Bambang_P said in Problem inserting record into QSqlTableModel of Postgresql: still don't have idea which part should be overrided... I'm giving up... Derive from QSqlTableModel and overwrite select() to adjust the mentioned value.
    • 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
      1454
      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
      1072
      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
      2576
      Views

      I did this: ui->comboBox->clear(); ((QSqlTableModel*)ui->comboBox->model())->select(); And it's working!
    • UNSOLVED QSqlTableModel, QSqltableView не работают в релизе.
      Russian • qtableview qsqltablemodel • • Oles  

      2
      0
      Votes
      2
      Posts
      821
      Views

      Так проверьте соединение при запуске. И может, драйвер для SQLite собран только дебаговый? Надо и релизный тоже собрать.
    • SOLVED Selecting a database while using QSqlTableModel
      General and Desktop • sql database qsqltablemodel • • spektro37  

      8
      0
      Votes
      8
      Posts
      2536
      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
      7774
      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
      1153
      Views

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

      4
      0
      Votes
      4
      Posts
      1522
      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
      0
      Votes
      8
      Posts
      4222
      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
      2412
      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
      7636
      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
      473
      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
      903
      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
      3864
      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
      5513
      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
      2402
      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
      835
      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
      2321
      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
      580
      Views

      No one has replied

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

      1
      0
      Votes
      1
      Posts
      821
      Views

      No one has replied

    • [SOLVED]Represent data as combo box or checkbox
      General and Desktop • qtableview qsqltablemodel custom delegate • • sachi  

      5
      0
      Votes
      5
      Posts
      1427
      Views

      Thank you for your help. I have subclass the QSortFilterProxyModel and set flags returns Qt::ItemIsUserCheckble. it worked well
    • QSqlTableModel saves resutls only when return is pressed & And auto sorting after the data is inserted
      General and Desktop • qtableview qsqltablemodel • • chronix  

      1
      0
      Votes
      1
      Posts
      418
      Views

      No one has replied

    • QSqlTableModel::insertRow() via QTableView
      General and Desktop • qtableview qt 5.5 qsqltablemodel • • chronix  

      1
      0
      Votes
      1
      Posts
      728
      Views

      No one has replied

    • [solved]Disabling editing on certain columns in QSqlTableModel
      General and Desktop • sql qsqltablemodel qt5.0.2 • • chronix  

      9
      0
      Votes
      9
      Posts
      3417
      Views

      You're welcome ! Since you have it working now, please update the thread title prepending [solved] so other forum users may know a solution has been found :)
    • [SOLVED] In Qt I want to make my model generation in a separate class for a QTableView
      General and Desktop • c++ qt5 qtableview qsqltablemodel • • ON7AMI - Jean Paul Mertens  

      5
      0
      Votes
      5
      Posts
      1325
      Views

      @mrjj OK but I use the class to encapsulate all data and logics on that data. The collection of all data to fill drop-down boxes, lists reports etc... are all in the class together with the hiding of the record data by get and put protection. So if I have to create an instance every time, I'll spend a whole needless bunch of heap for every list. If I use static functions it's more memory friendly :-) I have studied the model/view stuff of Qt almost the same thing was used by MS in the MFC time a 20 years ago, they also had a Data/View structure, but then we programmed still in C. So my ignorance is situated there that I have little C++ experience, just played a little with it in the time of Turbo Borland C++ a long time ago. Professionally I'm a MS programmer but for my son I'm developing a whole suite on Linux and Mono did not give me what I was used to so I switched to Qt and C++. This way the old man has to study again. But it keeps the mind young... Thanks a lot Jean Paul