Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to connect rowCountChanged to a slot

here is what i tend to design: when the tablewidget changes(say its rowcount), the label will show the rowcount.But when i tried it, Qtcreator says: Object::connect: No such signal QTableWidget::rowCountChanged(int,int) in ..\ui\mainwindow.cpp:55

why? rowCountChanged(int, int) is one slot inherited from QTableView, i think...

Thanks

like image 838
Fay100 Avatar asked Sep 16 '25 13:09

Fay100


1 Answers

As merlin said, Thats a protected slot.

But you can ask for the underlying model:

(Since widget inherits from tableView which inherits from AbstractView)

QAbstractItemModel * QAbstractItemView::model () const

And connect to model signals:

void QAbstractItemModel::rowsInserted ( const QModelIndex & parent, int start, int end ) [signal]
void QAbstractItemModel::rowsRemoved ( const QModelIndex & parent, int start, int end ) [signal]

Here You got all model signals

In fact, there is another way i would explore:

Subclassing QTableWidget, (public) you will have access to that protected slot.

So, creating your own signal:

void YourTableWidget::rowCountChanged(int,int)
{
QTableWidget::rowCountChanged(int,int);
emit your_signal(...);

}
like image 117
trompa Avatar answered Sep 19 '25 06:09

trompa