Skip to content
  • 0 Votes
    15 Posts
    337 Views
    S
    To add on to this, I discovered why it was trying to insert NULL for relation fields. I did the select before setting my relations. And it wasn't enough to have a separate model load the related table. It has to be loaded in the QSqlRelationTableModel for it to work. So the very original comment here (sorry if this pings you) turned out to be 100% correct. I'm just also posting this here for future reference @JonB said in QSqlRecord forces null in composite primary key on QSqlTableModel::insertRecord: Isn't that actually a consequence of you using a QSqlRelationalTableModel? Isn't it that the Qt side expects to see in the related FoodData table/model an entry for the value of your food column in FoodDay table/model equal to it? You have "broken the contract" you establish with QSqlRelationalTableModel that Qt will see in-memory models maintaining the relationship? It is not good enough if you say the row does exist at the backend database side, if you want to use QSqlRelationalTableModel (you don't have to, it's only for value lookup) you must have the FK model/table up-to-date in memory.
  • 0 Votes
    8 Posts
    882 Views
    Pl45m4P
    @JonB said in QSqlTableModel setFilter => Unable to execute statement: ? Escaping the column names and doing everything more thoughtfully would have prevented the crash... so "range" instead of range etc... I think not only any select statements were influenced but the whole table itself. That's why the DHCP service didn't start up anymore ;)
  • 0 Votes
    10 Posts
    1k Views
    JonBJ
    @Christian-Ehrlicher said in QSql performance consideration/data flow design.: Ok, I would never consider those functions as replacement for stored procedure. I agree, but it is their documentation, I guess "Lite" means "lite" :)
  • 0 Votes
    5 Posts
    858 Views
    P
    @Christian-Ehrlicher said in problem with QSqlTableModel and unique_ptr ! QTableView has The data but show Nothing: ah I understand now , many Thanks bro <3 i will try another solution really I Appreciate Your PROFESSIONAL Support <3
  • 0 Votes
    4 Posts
    765 Views
    R
    From what I've seen online, the QValidator approach requires subclassing QItemDelegate and it's setData() method. How is this different from the last point suggested ?
  • 0 Votes
    11 Posts
    2k Views
    Chris KawaC
    @MH24 said: Should I have used a QSqlTableModel here instead? Can we use the default and subclassed one in same class? Models are for displaying in a view. You don't need a model to get data out of a database. Use QSqlQuery instead and as a local variable. You don't need to allocate everything dynamically if you only use it locally. You can construct a SQL query that will get you those unique values while you're at it. Simpler and shorter. So if I click 2nd button of any table all 2nd rows of all tables would be edit enabled Then the problem is still the same - you're writing a variable in one model and read different variables in different models. Either write the variable to all the models or read from a single place that you write to.
  • 0 Votes
    5 Posts
    1k Views
    P
    @SGaist said in QMenu And QSqlQueryModel translation problem !: QEvent::LanguageChange @ SGaist Hi bro <3 i didn't know about QEvent::LanguageChange before really thank you, i will check it <3
  • QSqlTableModel Filter

    Unsolved General and Desktop qsqltablemodel filter
    4
    0 Votes
    4 Posts
    1k Views
    Pl45m4P
    @JonB said in QSqlTableModel Filter: 'First name' LIKE '%Jacob%' lol, was checking the condition and haven't noticed that, because of the use of DataBase::COLUMN_FIRSTNAME
  • 0 Votes
    6 Posts
    1k Views
    VikramSamyV
    @JonB said in TableView not updated or refreshed unless column is resized and scroll bar move up and down few times: @VikramSamy I don't know, but a couple of observations: You are using a QSqlTableModel, so it should be emitting all the dataChanged() and rowsInnserted() signals itself. I would remove all your emits. YES REMOVED HistoryProxyModel->setDynamicSortFilter(false);: try setting this to true, any difference? NO, I need to disable the-sorting mechanism in the proxy model and do the sorting in the SQL Table model itself before I initialize table-model as the source-model for the Qsortproxymodel If you remove your proxy model temporarily does everything work? Ya the the VIEW is updated properly if proxy model is removed. Try starting from a Qt example with model + proxy model, does that work? YES I DID After a long gap, i just started to check this issue again, the previous behavior of the Table View was due to the flow of my code and it is because descending order SORTING mechanism enabled in the proxy-model, this caused the behavior as in 1st post. T //this was the issue HistoryProxyModel->setDynamicSortFilter(true); HistoryProxyModel->sort(1,Qt::DescendingOrder); As I wanted to show the last row as first row in the Table View, I enabled the DescendingOrder sorting in the proxy model first and then apply filtering, and this was the issue . but then I enabled the descending Order sorting on the SQL Table Model and Disabled it on the proxy model, now all works fine, The proxy model just do the filtering's only. i added the code below on my Qsql Table Model. //this was the solution - sort the Table model TableModel->setSort(1,Qt::DescendingOrder); and so i removed the sorting codes at the proxy model . I removed the below code:- //removed from proxy codes //HistoryProxyModel->sort(1,Qt::DescendingOrder) and now so far all works fine....
  • 0 Votes
    9 Posts
    2k Views
    Christian EhrlicherC
    It's or sure no problem of Qt or the QSqlTableModel - fix your access rights.
  • 0 Votes
    1 Posts
    414 Views
    No one has replied
  • 0 Votes
    5 Posts
    1k Views
    Christian EhrlicherC
    The QSqlTableModel needs a real PK, yes.
  • 0 Votes
    2 Posts
    412 Views
    Christian EhrlicherC
    @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.
  • Unable to edit QSqlTableModel from QML

    Unsolved QML and Qt Quick qsqltablemodel sqlite model model-view
    4
    0 Votes
    4 Posts
    1k Views
    sierdzioS
    @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.
  • 0 Votes
    41 Posts
    15k Views
    R
    Upgrading to Qt Version 5.15+ solved the issue.
  • 0 Votes
    7 Posts
    2k Views
    J
    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.
  • 0 Votes
    10 Posts
    2k Views
    T
    @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.
  • 0 Votes
    2 Posts
    599 Views
    JonBJ
    @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 ?
  • 0 Votes
    6 Posts
    1k Views
    JonBJ
    @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!
  • QTableView Empty ?

    Unsolved General and Desktop qtableview qsqltablemodel sqlite3
    18
    0 Votes
    18 Posts
    4k Views
    SGaistS
    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.