[PySide] DataMapper issues
Adrian Klaver
adrian.klaver at gmail.com
Sun Feb 17 00:19:06 CET 2013
OpenSuse 12.2
pyside 1.1.2-1.11
Python 2.7.3
I have the following and it will not save the data to the database:
class PlantForm(QtGui.QMainWindow):
def __init__(self, parent=None):
super(PlantForm, self).__init__(parent)
loader = QtUiTools.QUiLoader()
self.ui =
loader.load("/home/aklaver/software_projects/greenhouse_app/python_code/plant_app_qt/forms/plant_form.ui")
self.model = QtSql.QSqlTableModel(self, db=db)
self.model.setTable("plant1")
self.model.setSort(0, QtCore.Qt.AscendingOrder)
self.model.setEditStrategy(self.model.OnManualSubmit)
self.model.select()
self.dm = QtGui.QDataWidgetMapper(self)
self.dm.setSubmitPolicy(self.dm.ManualSubmit)
self.dm.setModel(self.model)
self.dm.addMapping(self.ui.plantNoLi, 0)
self.dm.addMapping(self.ui.commonLi, 1)
self.dm.addMapping(self.ui.genusLi, 2)
self.dm.addMapping(self.ui.speciesLi, 3)
self.dm.toFirst()
self.saveBtn = self.ui.saveBtn
self.saveBtn.clicked.connect(self.model.submitAll)
self.ui.show()
self.center()
def center(self):
qr = self.frameGeometry()
cp = QtGui.QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
I am obviously missing something, I am just not sure what?
I tried the above with OnFieldChange for the model and AutoSubmit for
the DataMapper. When I opened the form the first field would update to
its existing value bit then I could not change anything. The changed
value stick in the widget, they just do not get to the database.
Thanks,
--
Adrian Klaver
adrian.klaver at gmail.com
More information about the PySide
mailing list