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 &quot;toLast&quot;, &quot;toPervious&quot;, &quot;toNext&quot; , &quot;toFisrt&quot; doen&#39;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(&quot;NC&quot;)<br>        self.model.setRelation(REGIONS,<br>
                QSqlRelation(&quot;Regions&quot;,&quot;ID_Regions&quot;, &quot;Nom_regions&quot;))<br><br>        self.model.setRelation(COMMUNE,<br>                QSqlRelation(&quot;Communes&quot;, &quot;ID_Communes&quot;,&quot;Nom&quot;))<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(&quot;Nom_regions&quot;))<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(&quot;Nom&quot;))<br>        self.mapper.addMapping(self.communeComboBox, COMMUNE)<br><br>        self.mapper.toFirst()<br><br>        self.connect(firstButton, SIGNAL(&quot;clicked()&quot;),self.mapper, SLOT(&quot;toFirst()&quot;))<br>
        self.connect(prevButton, SIGNAL(&quot;clicked()&quot;), self.mapper, SLOT(&quot;toPrevious()&quot;))<br>        self.connect(nextButton, SIGNAL(&quot;clicked()&quot;),self.mapper, SLOT(&quot;toNext()&quot;))<br>        self.connect(lastButton, SIGNAL(&quot;clicked()&quot;),self.mapper, SLOT (&quot;toLast()&quot;))<br>
        self.connect(addButton, SIGNAL(&quot;clicked()&quot;),self.addRecord)<br>        self.connect(deleteButton, SIGNAL(&quot;clicked()&quot;),self.deleteRecord)<br>        self.connect(quitButton, SIGNAL(&quot;clicked()&quot;), self.done)<br>
#            QObject.connect(self.ui.pushButton_Quit, SIGNAL(&quot;clicked()&quot;),self.done)<br>#                QObject.connect(self.ui.pushButton_xls, SIGNAL(&quot;clicked()&quot;),self.saveExcel)<br><br>        self.setWindowTitle(&quot;Debug NC&quot;)<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 &gt;= 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 = &#39;D:/&#39;<br>    d = DIRECTORY + &#39;MiniNC_test.s3db&#39;<br>
<br>    db = QSqlDatabase.addDatabase(&quot;QSQLITE&quot;)<br>    db.setDatabaseName(d)<br>    if not db.open():<br>            QMessageBox.warning(None, &quot;Nouvelles constructions&quot;,<br>                QString(&quot;Database Error: %1&quot;).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>