当前位置: 代码迷 >> QT开发 >> Qt中secondaryColumnCombo->currentIndex()的疑问 (《c++ gui qt 4 编程》),该怎么处理
  详细解决方案

Qt中secondaryColumnCombo->currentIndex()的疑问 (《c++ gui qt 4 编程》),该怎么处理

热度:452   发布时间:2016-04-25 04:32:53.0
Qt中secondaryColumnCombo->currentIndex()的疑问 (《c++ gui qt 4 编程》)
Qt中secondaryColumnCombo->currentIndex()的疑问
(《c++ gui qt 4 编程》)
--
在书中52页中有这样一段代码:

C/C++ code
void MainWindow::sort(){    SortDialog dialog(this);    QTableWidgetSelectionRange range = spreadsheet->selectedRange();    dialog.setColumnRange('A' + range.leftColumn(),                          'A' + range.rightColumn());    if (dialog.exec()) {        SpreadsheetCompare compare;        compare.keys[0] =              dialog.primaryColumnCombo->currentIndex();        compare.keys[1] =              dialog.secondaryColumnCombo->currentIndex() - 1;        compare.keys[2] =              dialog.tertiaryColumnCombo->currentIndex() - 1;        compare.ascending[0] =              (dialog.primaryOrderCombo->currentIndex() == 0);        compare.ascending[1] =              (dialog.secondaryOrderCombo->currentIndex() == 0);        compare.ascending[2] =              (dialog.tertiaryOrderCombo->currentIndex() == 0);        spreadsheet->sort(compare);    }}


哪位大大能详细解释一下

C/C++ code
              dialog.primaryColumnCombo->currentIndex();        compare.keys[1] =              dialog.secondaryColumnCombo->currentIndex() - 1;        compare.keys[2] =              dialog.tertiaryColumnCombo->currentIndex() - 1;


这几句啊,实在是看不懂,为毛要-1啊(书上说考虑到“none”项,从当前项-1)。还有,currentIndex()函数的索引值怎么算啊,是不是上述代码中key[]最后的值为{0,0,1}啊(如果如书中P52图3.14所示,选中A1到C7)

------解决方案--------------------
组合框中没数据时返回-1 索引是从0开始的 因为组合框中的第一项是“none” 不在计算范围之内
------解决方案--------------------
探讨
组合框中没数据时返回-1 索引是从0开始的 因为组合框中的第一项是“none” 不在计算范围之内