Skip to content
  • 0 Votes
    4 Posts
    192 Views
    JonBJ

    As @mpergand says for your current situation: within your program make sure you call insertRows(), then any attached views will be notified and refresh accordingly. Depending on your Qt model type that should already be the case (e.g. for the QSql... models). If you claim to be doing that yet not seeing the update, make sure your two views are sharing the same model instance. If you have two separate model instances both open on the same underlying SQL database that is no use: Qt won't recognise that to propagate the signal notification from one instance to another.

    @jdent said in How do I refresh a model so it takes new rows added after its creation?:

    @jdent The new locations could be added directly to the Database by means of a client application - how do I refresh the locations displayed?

    Assuming you mean some other application, no matter what/how, updates the database you are using for your model, be aware that Qt offers no way of detecting this or acting on it. That would require (a) the native database/driver having a way of "notifying" other client applications such as yours that this has happened which most do not provide and (b) Qt having a way of receiving such a "notification" and acting on it/passing it onto you, which it does not. You would have to write your own code outside of Qt to handle this if it were possible (but probably not because of (a)).

    The only way you would see such a change is (a) if you were in charge of the other application such that it could send a message to your application via a socket or shared memory/semaphore or similar or (b) you will simply see the new data the next time you (happen to) fill the model from the database. To that end if you had to know you would have to set up e.g. a QTimer to keep re-querying the database in case it had changed, which obviously is not very efficient.

  • 0 Votes
    5 Posts
    805 Views
    fcarneyF

    If you use the the same model instance in more than one place they will always have the same index. This may, or may not be what you want. FYI

  • 0 Votes
    6 Posts
    1k Views
    SGaistS

    From the looks of it, you have to re-create the models when you change these settings.

  • 0 Votes
    9 Posts
    2k Views
    I

    I went with the Binding solution in the end :)

  • 0 Votes
    3 Posts
    4k Views
    F

    Thanks for the feedback.
    I have a follow up question though.

    Where are QML's default role names documented? I couldn't see the list. It would save me a lot of time. EDIT Here they are: link.
  • Updating model from UI

    Unsolved General and Desktop
    2
    0 Votes
    2 Posts
    748 Views
    jsulmJ

    @vmjafar Hi!

    Take a look at http://doc.qt.io/qt-5/model-view-programming.html