¿QSqlQuery, QSqlQueryModel y QSqlTableModel implementan adición, eliminación, modificación y consulta en la base de datos QT Mysql? código
Utilice las funciones insetrow(), setdata() y submitall() de qsqltablemodel para implementar increment; officeTable-gt; insertRow(0); ,?0 ),?fila); officeTable-gt;setData(officeTable-gt;index(0,?1),?newWnd-gt;imageFileEditor-gt;currentIndex()); ;index( 0,?2),?newWnd-gt;locationText-gt;text()); officeTable-gt;setData(officeTable-gt;index(0,?3),?newWnd-gt;countryText-gt; currentText() ); officeTable-gt; setData(officeTable-gt; index(0,?4),?newWnd-gt; descripciónEditor-gt; toPlainText(); p>Usar Las funciones removerow() y submitall() implementan la eliminación; int?officeCount?=?officeTable-gt; rowCount(); removeRow(id); ?lt;? officeCount?-?1;i) { officeTable-gt;setData(officeTable-gt;index(i,?0),?i } officeTable-gt;submitAll();
Usar la clase QSqlRecord La implementación setvalue ha sido cambiada;recordCurrentRow?=?officeTable-gt; record(id); setRecord(id? -?1,?recordCurrentRow ); officeTable-gt; submitAll();
Utilice el valor .de la clase QSqlRecord para realizar comparación y verificación
int?Dialog::findArtistId; (const?QString?amp; artista)
{
QSqlTableModel?*artistModel?=?model-gt; int?row?=?0; p>
while?(row?lt;?artistModel-gt;rowCount())?{
QSqlRecord?record?=?artistModel-gt;record(fila );
if?(record.value("artista")?==?artista)
return?record.value("id").toInt();
else
fila
}
retorno?addNewArtist(artista);}