PDA

View Full Version : delete record from qsqltable



robotics
7th June 2011, 06:48
please help
how to delete record from qsqltablemodel....
I have ideas about inserting data but I don't have idea about how to delete record from qsqltablemodel

ChrisW67
7th June 2011, 07:14
Have you even briefly read the QSqlTableModel docs? Does QSqlTableModel::removeRows() sound promising?

Your underlying SQL table will almost certainly need a defined primary key.

l0ner
7th June 2011, 12:21
Hi! I'm new here and new to Qt in general.
I'm trying to do the same thing. Since QSqlTableModel::removeRow() needs row index as argument, how can I get the index of selected row? I looked here: http://www.qtforum.org/article/14578/how-can-i-get-the-current-selected-row-in-a-qsqltablemodel.html but this doesn't seem to work. I get those errors while I try to compile:


soltys@ubuntu:~/qt/neurohelper_v0.2$ make
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_SQL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtSql -I/usr/include/qt4 -I. -o tableeditor.o tableeditor.cpp
tableeditor.cpp: In member function ‘void TableEditor::delRow()’:
tableeditor.cpp:80: error: ‘class QSqlTableModel’ has no member named ‘selectionModel’
tableeditor.cpp:81: error: ‘class QItemSelectionModel’ has no member named ‘selectionIndex’
tableeditor.cpp:85: error: no matching function for call to ‘QSqlTableModel::removeRow(const QModelIndex&)’
/usr/include/qt4/QtCore/qabstractitemmodel.h:314: note: candidates are: bool QAbstractItemModel::removeRow(int, const QModelIndex&)
make: *** [tableeditor.o] Error 1