August 7, 2012

Anas Al-Taji Anas Al-Taji
Lab Rat
14 posts

Inconvenient Behaviour: QSqlTableModel.removeRow()

 

Hi All,,

After updating PyQt version 4.8.5 to 4.9.4, QSqlTableModel.removeRow() has the following behavior:

  • Return True.
  • verticalHeaderData changed to “!”.
  • Row content erased (Record fields become blank in the QTableView)
  • Calling submitAll() works as expected.

More Info:

  • I tried to install a fresh copy of Python v2.7 & PyQt v4.9.4 to another machine but the problem persist.
  • Downgrading the PyQt version to 4.8.5 seems to solve the problem.

Code: (This is the exact code used for testing on both versions)

  1.     mw = QMainWindow()
  2.    
  3.     model = QSqlTableModel(None, connectionManager().getConnection())
  4.     model.setTable("vouchertypes")
  5.     model.setEditStrategy(model.OnManualSubmit)
  6.     model.select()
  7.  
  8.     tv = QTableView(mw)
  9.     tv.setModel(model)
  10.    
  11.     bt = QPushButton("Delete", mw)
  12.     bt.clicked.connect(lambda: model.removeRow(tv.currentIndex().row()))
  13.     mw.show()

  • If some can help providing me a previous PyQt ver(4.9.1 or 4.9.2 or 4.9.3) this might solve the problem for the current time.

Appreciate any kind of help.

2 replies

August 7, 2012

Andre Andre
Area 51 Engineer
6076 posts

You are not describing the actual change in behavior, nor what you percieve to be the problem.

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

August 7, 2012

Anas Al-Taji Anas Al-Taji
Lab Rat
14 posts

sorry Andre, i will try to explain better now.

the problem is: Why calling QSqlTableModel.removeRow() erase the row content in the view and model. (so, calling record.field().value().toString() for the removed row —without calling submitAll()— returns empty string for all fields.!!)

doing so with PyQt v4.8.5 will keep the row contents untouched until i call submitAll() for actual deletion.

Thanks for your patience.

 
  ‹‹ Strict knowledge of subset of properties involved in a userdefined script      Put C++ class into QML window ››

You must log in to post a reply. Not a member yet? Register here!