Results 1 to 4 of 4

Thread: Problem with simple Model-View in Qt4.3

  1. #1
    Join Date
    Jan 2006
    Posts
    13
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy Problem with simple Model-View in Qt4.3

    The code below (a very simple QTableView example) works fine under Qt4.2.3 but it does not work with Qt4.3.
    No idea why. Any help is greatly appreciated.
    Thanks
    Chris
    Attached Files Attached Files

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with simple Model-View in Qt4.3

    The problem is that you did not call beginInsertRows/endInsertRows.
    You must call them before/after setModelData, in populate();

    Be careful with the parameters for beginInsertRows.


    Regards

  3. #3
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with simple Model-View in Qt4.3

    Actually, the problem is somewhere else. Forget what I said before.
    The docs say:
    Resets the model to its original state in any attached views. When a model is reset it means that any previous data reported from the model is now invalid and has to be queried for again.
    When a model radically changes its data it can sometimes be easier to just call this function rather than emit dataChanged() to inform other components when the underlying data source, or its structure, has changed.
    You were clearing the data and also reset the model before recreating the back store. This happens in function TableModel: populate.

    The error was that when you called reset on the model, it tried to reinitialize with new data ( header views, etc ). But there was no new data, because it was created after you reset the model.

    The solution is to call reset just after setModelData(), in populate.
    This way the model will have an update source available.

    Regards

  4. The following user says thank you to marcel for this useful post:

    ccf_h (17th June 2007)

  5. #4
    Join Date
    Jan 2006
    Posts
    13
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with simple Model-View in Qt4.3

    Great, that worked!!! Thanks a lot. :-)
    I still wonder why it worked under Qt4.2 and earlier. They seem to have changed a lot internally.

Similar Threads

  1. hierarchical model in a flat view
    By gniking in forum Qt Programming
    Replies: 4
    Last Post: 10th November 2009, 20:17
  2. Table Model / View Problem -- Data Not Displaying
    By jhendersen in forum Qt Programming
    Replies: 1
    Last Post: 22nd April 2007, 06:45
  3. Model, View and Proxy
    By No-Nonsense in forum Qt Programming
    Replies: 2
    Last Post: 21st November 2006, 08:50
  4. Model - View Programming doubt.
    By munna in forum Qt Programming
    Replies: 4
    Last Post: 28th April 2006, 13:01
  5. Replies: 6
    Last Post: 20th April 2006, 10:23

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.