2010-10-14 61 views
7

我正在使用Qtableview和QsqlTableModel来填充表数据。我想根据列标题上的用户选择对列进行排序。Qt Qtableview没有获取标题项目点击的信号

我试着在QTableView sorting signal?用于获取信号(从QTableView中取得水平头和连接提到的路信号sectionclicked(INT逻辑索引),但相同的信号时,我的列标题点击是没有得到发射。

请找出其中连接完成的代码:

成员变量:

QHeaderView *m_horiz_header; 

.cpp文件

m_sqltablemodel->setTable(tabel_name); 
m_sqltablemodel->setEditStrategy(QSqlTableModel::OnManualSubmit); 
m_sqltablemodel->select(); 

m_horiz_header= m_table_view->horizontalHeader(); 
connect(m_horiz_header, SIGNAL(sectionClicked (int logicalIndex)), 
    this, SLOT(on_sectionClicked (int logicalIndex))); 

分拣槽函数:

void class::on_sectionClicked (int logicalIndex) 
{ 
    m_horiz_header->setSortIndicator(logicalIndex, Qt::AscendingOrder); 
    m_table_view->sortByColumn(logicalIndex); 
} 

此功能没有得到调用,点击列标题时。

你能帮我吗?如何做到这一点,我出错了?

在此先感谢。

+0

相关主题:http://stackoverflow.com/questions/24714130/qt-5-3-qtreeview-clickable-header-data – neuronet 2015-02-16 15:40:54

回答

7

我得到了信号连接失败的原因。

参数名称不应在连接中提及。

connect(m_horiz_header, SIGNAL(sectionClicked(int)), this, SLOT(on_sectionClicked(int))); 

通过修改上面的代码就像这样,它的工作。