Results 1 to 7 of 7

Thread: Clearing data model

  1. #1
    Join Date
    Feb 2007
    Posts
    48
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Clearing data model

    I have a QStandardDataModel that is associated with a table view. There is a rest button on the form. When the reset is clicked it calls a method that clears the data model using clear().

    I thought that this would eliminate eveything associatd with the model so that the next time I use the model I'm starting at the begining. That is not the case.

    There are 4 columns of data. After the clear(), when I populated the model again I have 8 columns (last 4 being empty). And this continues.

    How do I effectively clear the data model so that on the next resue it only displays the data set and not empty items.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Clearing data model

    Quote Originally Posted by db View Post
    I thought that this would eliminate eveything associatd with the model so that the next time I use the model I'm starting at the begining. That is not the case.

    There are 4 columns of data. After the clear(), when I populated the model again I have 8 columns (last 4 being empty). And this continues.
    Are you sure it's not a bug in your code? This is what QStandardItemModel::clear() docs promise:
    Removes all items (including header items) from the model and sets the number of rows and columns to zero.
    J-P Nurmi

  3. #3
    Join Date
    Feb 2007
    Posts
    48
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Clearing data model

    I been through the code several times... but I'll go back through it again. I agree, I thought that that was all i needed to do to clear it.

  4. #4
    Join Date
    Feb 2007
    Posts
    48
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Clearing data model - Update

    Further investigation of my code shows that the clear() is not completely working because I set header labels uing model.setHorizontalHeaderLabel().

    Appearently cleaer() does not get rid of the header labels. I have been going through the documentation and can't seem to find the correct call to clear the header labels so that the clear() will clear the table.

    What is the call?

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Clearing data model

    Hmm, but calling setHorizontalHeaderLabels() again and again won't increase the column count, does it? Could you write a simple and small test application which shows the problem you're encountering?
    J-P Nurmi

  6. #6
    Join Date
    Feb 2007
    Posts
    48
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Clearing data model

    OK. I have provided a stripped version of my code. It has only the items needed to show the problem. If you comment out the setHorizontalHeader call you'll set that it acts OK. Setting the header causes the error.

    Thanks
    Attached Files Attached Files

  7. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Clearing data model

    "QStringList headerLabels" is a member variable. Three strings are being added every time CFlightPlan::createModel() gets called. First time it contains properly 3 items, second time it contains 6 items and so on...
    J-P Nurmi

  8. The following user says thank you to jpn for this useful post:

    db (18th February 2008)

Similar Threads

  1. QMap model data
    By gyre in forum Newbie
    Replies: 3
    Last Post: 9th December 2007, 22:19
  2. Model - data
    By gyre in forum Newbie
    Replies: 1
    Last Post: 9th December 2007, 19:49
  3. Data model
    By steg90 in forum Qt Programming
    Replies: 3
    Last Post: 17th September 2007, 12:14
  4. Custom Model Class
    By mattjgalloway in forum Qt Programming
    Replies: 12
    Last Post: 4th June 2007, 17:30
  5. Informing a model its data has changed
    By saknopper in forum Newbie
    Replies: 3
    Last Post: 17th January 2007, 19:58

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.