Navigation

    Qt Forum

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

    • UNSOLVED QTableView Empty ?
      General and Desktop • qtableview qsqltablemodel sqlite3 • • R-P-H  

      18
      0
      Votes
      18
      Posts
      384
      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 models quick controls qml components • • ivarec  

      1
      0
      Votes
      1
      Posts
      97
      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
      459
      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
      622
      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
      864
      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
      2121
      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
      605
      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
      1838
      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
      1109
      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
      812
      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
      1984
      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
      778
      Views

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

      8
      0
      Votes
      8
      Posts
      2270
      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
      7272
      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
      1075
      Views

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

      4
      0
      Votes
      4
      Posts
      1444
      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
      3921
      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
      2315
      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
      6955
      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
      465
      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
      864
      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
      3727
      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
      5204
      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
      2233
      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
      774
      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
      2152
      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
      530
      Views

      No one has replied

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

      1
      0
      Votes
      1
      Posts
      794
      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
      1400
      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
      403
      Views

      No one has replied

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

      1
      0
      Votes
      1
      Posts
      694
      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
      3239
      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
      1302
      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
    • Strange things happening to QSqlTableModel (while inserting, deleting, updating)
      General and Desktop • qsqltablemodel • • Charlie42  

      1
      0
      Votes
      1
      Posts
      391
      Views

      No one has replied

    • QSqlTabelModel - QTableView - insertRecord not editable [solved]
      General and Desktop • qtableview qsqltablemodel • • Andy314  

      5
      0
      Votes
      5
      Posts
      1486
      Views

      An empty string should disable the filter. However, if the underlying select it active then it will trigger calling select() which resets the model.
    • [Solved] QTest issue creating object to test with
      General and Desktop • c++ qt 5.4 qsqltablemodel test • • Sam2304  

      6
      0
      Votes
      6
      Posts
      3394
      Views

      @Sam2304 you are welcome Well, sometimes "we programmers do not see the forest because of trees" ;) Glad, that it worked out for you.
    • QSqlTableModel read only
      General and Desktop • sql sqlite qsqltablemodel • • GrahamL  

      2
      0
      Votes
      2
      Posts
      963
      Views

      Hi, You can to the same here, subclass QSqlTableModel and reimplement the flags function
    • QSqlTableModel saving changes problems.
      General and Desktop • qsqltablemodel • • Zereo  

      1
      0
      Votes
      1
      Posts
      531
      Views

      No one has replied