currentRowChanged 的注意事项

简介:

Qt中的表单控件QListWidget类提供了许多信号函数,可以和用户交互,其中有个currentRowChanged ( int currentRow ) 是检测当前选中行是否发生了改变,如果改变了,该信号函数被触发。

void QListWidget::currentRowChanged ( int currentRow ) [signal]

This signal is emitted whenever the current item changes.
currentRow is the row of the current item. If there is no current item, the currentRow is -1.

我们要注意的是最后一句话,当没有当前项时,currentRow 赋值为-1,由于有这点存在,所以再写该信号函数的内容开始,一定要先判断currentRow的值是否大于等于0,若忽略了这一步,在下面直接用currentRow当做参数取访问数组时会出错,而通常这错误得费老半天劲才能找的出来,正确写法如下: 

void YourClass::on_lwidget_currentRowChanged(int currentRow) {
    // Note: lwdiget is the object name of listwidget
    if (currentRow >= 0) {
        // Implement here!
    }
}

本文转自博客园Grandyang的博客,原文链接:currentRowChanged 的注意事项,如需转载请自行联系原博主。

相关文章
|
6月前
|
存储 算法 测试技术
关于HOperatorSet.CountChannels的注意事项
关于HOperatorSet.CountChannels的注意事项
|
2月前
|
前端开发 JavaScript API
reactAPI讲解以及注意事项
reactAPI讲解以及注意事项
12 2
|
网络协议
AFNetWork3.0使用注意事项
AFNetWork3.0使用注意事项
95 0
|
Python
函数注意事项
# 函数的位置参数必须要传实参,可以按位置,也可以按关键字传 # 函数的默认参数可以不传实参,可以按位置,也可以按关键字 # 不定长参数*args只收集位置参数形成元组,不定长参数应放在后面,要不会把实参当做位置参数然后报错 # 用**,只要定义了关键字参数,以后针对这个参数传值就必须是关键字形式...
960 0
|
关系型数据库 PostgreSQL