Qt World Summit: Register Today!

How to insert data rows to QProxyModel?

  • @this->beginInsertRows(QModelIndex(),this->rowCount(),List.length());
    for (int i=0;i<List.length();i++){

    I can't insert with above code..
    How can I insert QList<QStandardItem*> List into that QProxyModel?
    Or need another QList<????*> List ?


  • Hi zither,

    If the proxy model is the QSortFilterProxyModel it will call the source modles functions for that. If the source model does not support inserting rows, it will do nothing.

    Or do you have a custom implemented proxy model? then perhaps, it's missing some implementation...

  • Hi Gerolf,

    I'm making custom QProxyModel which source Model is QSqlQueryModel, I would like to add new rows to QProxyModel which will show to QListView.
    @QSqlQueryModel -> QProxyModel ->QListView;@
    How can I insert new rows for that?


  • insertRows empty implementation does nothing. You have to do the insert pon your own, so e.g. call the source models insertRow function instead of the base implementation.

  • My Source Model is QSqlQueryModel which is read-only..

    So, I have to change type of my source Model?
    Is there any model which can handle one data source & inserting of data via Model?

  • What do you try to achieve?

    Do you just want to insert data temporarily? then QProxyModel is a a possibility. But you have to handle it on your own. There is no default model for such things. You have abstract models (only base classes), proxy models (QSFPM) which do not implement inserting data by default, SQL models which allow inserting data but that is only possible if the model is not readonly.

  • I made a search method for SQLite Database.
    So, I choose QSqlQueryModel as it source. Then, I need to insert some XML data from another at the same time. So, I have to insert new rows to that Model which link to ModelView.

    Plz help me to pass that problem...


  • Why are you starting a new topic on that? You have several topics on this already. Please stick to one topic for one question.

Log in to reply