Solved checking duplicate data Tableview ?
-
checking duplicate data in Tableview after entereddata from line edit to Tableview,with database?
-
checking duplicate data in Tableview after entered data from line edit to Tableview,which is connected with database?
-
bool isDuplicate(const QAbstarctItemModel* const model, const QVariant& newValue, int column, int role = Qt::EditRole, const QModelIndex& parent = QModelIndex()){ const int rowCount = model->rowCount(parent); for(int i=0;i<rowCount ;++i){ if(model->index(i,column,parent).data(role) == newValue) return true; } return false; }
-
how to call this function into pushbutton function....... is this function inherited from any class?
-
create a slot, connect it to QPushButton::clicked signal and call the isDuplicate function from there
-
If you are using sqlite, mariaDB etc, you can use sql command
ON CONFLICT IGNORE
to do the jobs.
If you are handle the data by yourself and the data is small(several hundreds or thousands?), solution of VRonin is good enough. If the data is very big(ex : 0.5 million), you can inherit QAbstractTableModel and give boost::multi_index a shot.
-
I have created slot like this
connect(button, SIGNAL(clicked()), SLOT(isDuplicate(const QAbstarctItemModel* const model, const QVariant& newValue, int column, int role = Qt::EditRole, const QModelIndex& parent = QModelIndex())));giving errors
error: ‘QAbstarctItemModel’ does not name a type
bool isDuplicate(const QAbstarctItemModel* const model, const QVariant& newValue, int column, int role = Qt::EditRole, const QModelIndex& parent = QModelIndex())error: request for member ‘rowCount’ in ‘(const int)model’, which is of non-class type ‘const int’
const int rowCount = model->rowCount(parent); -
is there way to do it ....using qsqlquery.......?
-
@veera said in checking duplicate data Tableview ?:
connect(button, SIGNAL(clicked()), SLOT(isDuplicate(const QAbstarctItemModel* const model, const QVariant& newValue, int column, int role = Qt::EditRole, const QModelIndex& parent = QModelIndex())));
What is this?
Just add a slot and in this slot use isDuplicate - don't use isDuplicate as slot! -
in the header file private slots i have declared and defined in mainwindow.cpp function calling in particular pushbutton ....is that right?
-
@veera said in checking duplicate data Tableview ?:
is there way to do it ....using qsqlquery.......?
Yes, please check QSqlTableModel, if this class do not meet your requirements, you may need to create a custom model.
@veera said in checking duplicate data Tableview ?:
in the header file private slots i have declared and defined in mainwindow.cpp function calling in particular pushbutton ....is that right?
Nope, there are two problems
1 : arguments mismatch. Type and arguments number need to match with each other
2 : you should not connect your slot with default parametersI suggest you study the documents of signal and slot again
-
i am a beginner of qt .....please give me some examples for better understanding
-
finally i have solved this issue using unique key constraints while creating the table ..............