Results 1 to 3 of 3

Thread: QDataWidgetMapper: setCurrentIndex causes GUI to hang

  1. #1
    Join Date
    Feb 2011
    Posts
    3
    Qt products
    Platforms
    Unix/X11

    Default QDataWidgetMapper: setCurrentIndex causes GUI to hang

    I have been building a GUI data-entry application that accepts input from a user and saves it to a database. I have been using PyQt to develop the application, which has been quite the learning experience for me, but one that I have negotiated well with the help of Mark Summerfield's book (which I recommend). However, I have encountered a problem that truly frustrates me.

    I have a data entry dialog in which I am implementing a QSqlRelationalTableModel object for the database model and a QDataWidgetMapper object to map the widget states to it. When I press the Add Entry button in my dialog, the current record gets saved if there are any changes and a new row is written to the data model. I've set this up for all of the other dialogs in my application and it works without any problems. But in this dialog, when the execution hits self.mapper.setCurrentIndex(row), the GUI hangs and forces me to end the process through the process manager. I've verified that the mapper is pointing to the model and that a new row is indeed being written to the model. I do not know why the code is not working when I have used exactly the same code for other implementations without any problems.

    For the record, I am using PyQt 4.7.2/Qt 4.6.2 with Python 2.6.5 on a Ubuntu Linux machine (64-bit version 10.04 Lucid Lynx).

    Here is the code in the class constructor:
    Qt Code:
    1. #
    2. # underlying database model (tbl_penaltyshootouts)
    3. # because of foreign keys, instantiate QSqlRelationalTableModel and define relations to it
    4. self.model = QSqlRelationalTableModel(self)
    5. self.model.setTable("tbl_penaltyshootouts")
    6. self.model.setRelation(PenShootoutEntryDlg.ROUND_ID, QSqlRelation("tbl_rounds", "round_id", "round_desc"))
    7. self.model.setRelation(PenShootoutEntryDlg.LINEUP_ID, QSqlRelation("lineup_list", "lineup_id", "player"))
    8. self.model.setRelation(PenShootoutEntryDlg.OUTCOME_ID, QSqlRelation("tbl_penoutcomes", "penoutcome_id", "po_desc"))
    9. self.model.setSort(PenShootoutEntryDlg.ID, Qt.AscendingOrder)
    10. self.model.select()
    11.  
    12. # define mapper
    13. # establish ties between underlying database model and data widgets on form
    14. self.mapper = QDataWidgetMapper(self)
    15. self.mapper.setSubmitPolicy(QDataWidgetMapper.ManualSubmit)
    16. self.mapper.setModel(self.model)
    17. penaltyDelegate = GenericDelegate(self)
    18. penaltyDelegate.insertColumnDelegate(PenShootoutEntryDlg.LINEUP_ID, ShootoutPlayerComboBoxDelegate(self))
    19. penaltyDelegate.insertColumnDelegate(PenShootoutEntryDlg.ROUND_ID, ShootoutRoundComboBoxDelegate(self))
    20. self.mapper.setItemDelegate(penaltyDelegate)
    21. self.mapper.toFirst()
    22.  
    23. [...]
    24. self.connect(self.addEntry, SIGNAL("clicked()"), self.addRecord)
    To copy to clipboard, switch view to plain text mode 

    Here is the addRecord() code:

    Qt Code:
    1. def addRecord(self):
    2. """Adds new record at end of entry list."""
    3. # save current index if valid
    4. row = self.mapper.currentIndex()
    5. if row != -1:
    6. if self.isDirty(row):
    7. if MsgPrompts.SaveDiscardOptionPrompt(self):
    8. if not self.mapper.submit():
    9. MsgPrompts.DatabaseCommitErrorPrompt(self, self.model.lastError())
    10. else:
    11. if row == 0:
    12. self.updateLinkingTable(self.penOpenerMapper, self.penFirstSelect)
    13. else:
    14. self.mapper.revert()
    15. return
    16.  
    17. row = self.model.rowCount()
    18. self.model.insertRow(row)
    19. self.mapper.setCurrentIndex(row)
    To copy to clipboard, switch view to plain text mode 

    If you want or need to see more code, let me know.

  2. #2
    Join Date
    Feb 2011
    Posts
    3
    Qt products
    Platforms
    Unix/X11

    Default Re: QDataWidgetMapper: setCurrentIndex causes GUI to hang

    I found the source of the hanging GUI. It turns out to have nothing to do with the mapper - there was an infinite loop going on in one of the item delegates!

    Now I feel a bit silly...

  3. #3
    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: QDataWidgetMapper: setCurrentIndex causes GUI to hang

    We all have those moments... why do you think you should be any different?

Similar Threads

  1. QComboBox: setCurrentIndex() is not working?
    By Astronomy in forum Qt Programming
    Replies: 12
    Last Post: 12th August 2015, 21:51
  2. QComboBox setCurrentIndex doesn't work
    By trallallero in forum Qt Programming
    Replies: 4
    Last Post: 8th November 2011, 08:37
  3. QListView - setCurrentIndex()
    By Tomasz in forum Newbie
    Replies: 1
    Last Post: 29th December 2010, 11:48
  4. setCurrentIndex() doesn't display cursor(bounding rect)
    By DIMEDROLL in forum Qt Programming
    Replies: 0
    Last Post: 5th November 2008, 06:24
  5. QFileDialog hang ups
    By baray98 in forum Qt Programming
    Replies: 1
    Last Post: 27th October 2007, 02:56

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.