[PySide] DataMapper issues

Adrian Klaver adrian.klaver at gmail.com
Sun Feb 17 04:05:30 CET 2013


On 02/16/2013 07:01 PM, Srini Kommoori wrote:
> Can you set/get the sql db using python?
>
> As you are on Python, I would use sqlalchemy or native python bindings
> for the sql interface and test it out.

The database connection works. I get the correct values in the lineEdit 
widgets. As I mentioned when I set up OnFieldChange and AutoSubmit the 
form would update the first field on entry.
>
>
>
> On Sat, Feb 16, 2013 at 3:19 PM, Adrian Klaver <adrian.klaver at gmail.com
> <mailto:adrian.klaver at gmail.com>> wrote:
>
>     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 <http://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 <mailto:adrian.klaver at gmail.com>
>     _______________________________________________
>     PySide mailing list
>     PySide at qt-project.org <mailto:PySide at qt-project.org>
>     http://lists.qt-project.org/mailman/listinfo/pyside
>
>


-- 
Adrian Klaver
adrian.klaver at gmail.com



More information about the PySide mailing list