一杯清酒邀明月
天下本无事,庸人扰之而烦耳。

Here is an example of how you can get a table cell's text when clicking on it.

Suppose a QTableView defined in some MyClass class. You need to connect the clicked signal to your own MyClass::onTableClicked() slot, as shown below:

connect(tableView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(onTableClicked(const QModelIndex &)));

注意:QT的connect只写参数类型,不写参数名。

Slot implementation:

1 void MyClass::onTableClicked(const QModelIndex &index)
2 {
3     if (index.isValid()) 
4     {
5         QString cellText = index.data().toString();        
6     }
7 }

 

posted on 2020-04-14 14:26  一杯清酒邀明月  阅读(3687)  评论(1编辑  收藏  举报