Hello,<br><br>I am creating a database using PyQt and QtSql module. My problem is that no new data is recorded, and impossible to delete something.Slots "toLast", "toPervious", "toNext" , "toFisrt" doen't work. <br>
<br>My database has only one row to test the recording of new data.<br><br>There is a part of my code (code concerning the layout can be add if necessary bt the GUI is correctly displayed).<br><br>Thanks in advance for your help.<br>
<br>Anne-Laure<br><br>#--------------------------------------------------------<br><br> self.model = QSqlRelationalTableModel(self)<br> self.model.setTable("NC")<br> self.model.setRelation(REGIONS,<br>
QSqlRelation("Regions","ID_Regions", "Nom_regions"))<br><br> self.model.setRelation(COMMUNE,<br> QSqlRelation("Communes", "ID_Communes","Nom"))<br>
<br> self.model.setSort(ID_NC, Qt.AscendingOrder)<br> self.model.select()<br><br> self.mapper = QDataWidgetMapper(self)<br> self.mapper.setSubmitPolicy(QDataWidgetMapper.ManualSubmit)<br> self.mapper.setModel(self.model)<br>
self.mapper.setItemDelegate(QSqlRelationalDelegate(self))<br><br> self.mapper.addMapping(self.IDBatEdit, ID_BAT)<br> self.mapper.addMapping(self.rueEdit, RUE)<br> self.mapper.addMapping(self.numRueEdit, NUMERO)<br>
self.mapper.addMapping(self.NPAEdit, NPA)<br> self.mapper.addMapping(self.localiteEdit, LOCALITE)<br><br> relationModel_Reg = self.model.relationModel(REGIONS)<br> relationModel_Reg.setSort(REGIONS,Qt.AscendingOrder)<br>
self.regionsComboBox.setModel(relationModel_Reg)<br> self.regionsComboBox.setModelColumn(<br> relationModel_Reg.fieldIndex("Nom_regions"))<br> self.mapper.addMapping(self.regionsComboBox, REGIONS)<br>
<br> relationModel_NComm = self.model.relationModel(COMMUNE)<br> relationModel_NComm.setSort(COMMUNE,Qt.AscendingOrder)<br> self.communeComboBox.setModel(relationModel_NComm)<br> self.communeComboBox.setModelColumn(<br>
relationModel_NComm.fieldIndex("Nom"))<br> self.mapper.addMapping(self.communeComboBox, COMMUNE)<br><br> self.mapper.toFirst()<br><br> self.connect(firstButton, SIGNAL("clicked()"),self.mapper, SLOT("toFirst()"))<br>
self.connect(prevButton, SIGNAL("clicked()"), self.mapper, SLOT("toPrevious()"))<br> self.connect(nextButton, SIGNAL("clicked()"),self.mapper, SLOT("toNext()"))<br> self.connect(lastButton, SIGNAL("clicked()"),self.mapper, SLOT ("toLast()"))<br>
self.connect(addButton, SIGNAL("clicked()"),self.addRecord)<br> self.connect(deleteButton, SIGNAL("clicked()"),self.deleteRecord)<br> self.connect(quitButton, SIGNAL("clicked()"), self.done)<br>
# QObject.connect(self.ui.pushButton_Quit, SIGNAL("clicked()"),self.done)<br># QObject.connect(self.ui.pushButton_xls, SIGNAL("clicked()"),self.saveExcel)<br><br> self.setWindowTitle("Debug NC")<br>
<br><br><br> def done(self, result=None):<br> self.mapper.submit()<br> QDialog.done(self, True)<br><br> def addRecord(self):<br> row = self.model.rowCount()<br> self.mapper.submit()<br> self.model.insertRow(row)<br>
self.mapper.setCurrentIndex(row)<br> self.IDBatEdit.setFocus()<br><br><br><br> def deleteRecord(self):<br> # record = self.model.record(index.row())<br> row = self.mapper.currentIndex()<br>
self.model.removeRow(row)<br> self.model.submitAll()<br> if row + 1 >= self.model.rowCount():<br> row = self.model.rowCount() -1<br> self.mapper.setCurrentIndex(row)<br><br><br> def saveRecord(self):<br>
row = self.mapper.currentIndex()<br> self.mapper.submit()<br> self.mapper.setCurrentIndex(row)<br><br><br>def main():<br> app = QApplication(sys.argv)<br><br> DIRECTORY = 'D:/'<br> d = DIRECTORY + 'MiniNC_test.s3db'<br>
<br> db = QSqlDatabase.addDatabase("QSQLITE")<br> db.setDatabaseName(d)<br> if not db.open():<br> QMessageBox.warning(None, "Nouvelles constructions",<br> QString("Database Error: %1").arg(db.lastError().text()))<br>
sys.exit(1)<br> form = ncGUI()<br> form.show()<br><br> sys.exit(app.exec_())<br>main()<br><br>#-----------------------------------------------------------------------------------<br>