PDA

View Full Version : in QAbstractItemView rowsAboutToBeRemoved() give wrong model index



moh.gup@gmail.com
10th July 2012, 18:44
Hi
,I had impelemented QAbstractItemView and i m setting QStandarditemmodel as model.
When i using removerow(0) in model,then i am not getting any correct index in rowsAboutToBeRemoved of Qabractitemview,
But its look like row get delted before before calling slots.Please let me know how to get vaild index in rowsAboutToBeRemoved

moh.gup@gmail.com
15th July 2012, 15:17
ANY IDEA about my problem or its a qt bug?

wysota
15th July 2012, 15:29
It's hard to help you since you didn't show us any of your code.

This works fine for me:


#include <QtGui>

class Dummy : public QObject {
Q_OBJECT
public:
Dummy() : QObject() {}
public slots:
void check(const QModelIndex &parent, int start, int end) {
qDebug() << Q_FUNC_INFO << start << end;
}
};

#include "main.moc"

int main(int argc, char **argv) {
QCoreApplication app(argc, argv);
QStandardItemModel model(4,2);
Dummy d;
QObject::connect(&model, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)), &d, SLOT(check(QModelIndex, int, int)));
model.removeRow(0);
return 0;
}

Result: void Dummy::check(const QModelIndex&, int, int) 0 0