Results 1 to 3 of 3

Thread: What is the best way to support CheckBox in a QSqlTableModel ?

  1. #1
    Join Date
    Apr 2011
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default What is the best way to support CheckBox in a QSqlTableModel ?

    Hello all,

    I'm searching for a "generic" solution to store checkbox status in a QSqlTableModel. In fact, I have a custom QSqlTableModel with a QSet<QPersistenModelIndex> to store all modelindex where the box are checked.
    Of course i have redefined data(), setData(), flag(), removeRows().
    --> My simple implementation is here on github :
    sqltablemodelcheckable.cpp
    sqltablemodelcheckable.h

    The problem is : when I call "SubmitAll()", all my QPersistenModelIndex are automatically set to invalid. Are the modelindex that they refers are deleted, then recreated or something like that (???)

    Does someone know why ? Or can indicate me another solution.
    Thanks a lot.
    Last edited by sOuSiX; 20th April 2011 at 18:50.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: What is the best way to support CheckBox in a QSqlTableModel ?

    When you submitAll() all selections and indexes are invalidated and the model is repopulated from the underlying database. The new query might return rows in a different order, more rows, or less rows (e.g. if another process has removed rows in the meantime) so a row-column pair (QModelIndex or QPersistentModelIndex) may not be pointing at the same data afterward.

    You would need to store a unique row id from your data and column for each checked cell before the submit and recheck them after the submit. Alternatively, you could store the checked columns as a bitmap in an extra column of the table.

  3. The following user says thank you to ChrisW67 for this useful post:

    sOuSiX (21st April 2011)

  4. #3
    Join Date
    Apr 2011
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: What is the best way to support CheckBox in a QSqlTableModel ?

    Thanks =)

Similar Threads

  1. Replies: 8
    Last Post: 30th March 2011, 20:06
  2. checkbox
    By fluefiske in forum Newbie
    Replies: 3
    Last Post: 5th October 2010, 22:41
  3. QTableView with a checkbox
    By maxpower in forum Qt Programming
    Replies: 17
    Last Post: 18th February 2007, 09:45
  4. checkbox
    By nErnie in forum Qt Programming
    Replies: 1
    Last Post: 25th September 2006, 21:59
  5. checkBox
    By mickey in forum Qt Programming
    Replies: 8
    Last Post: 1st April 2006, 23:05

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.