[PySide] DataMapper issues

Srini Kommoori vasure at gmail.com
Sun Feb 17 04:01:03 CET 2013


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.



On Sat, Feb 16, 2013 at 3:19 PM, Adrian Klaver <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 = 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
> _______________________________________________
> PySide mailing list
> PySide at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/pyside
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20130216/1d51d3ec/attachment.html>


More information about the PySide mailing list