• 4067阅读
  • 2回复

请教以下关于QDirModel代码的问题【已解决】 [复制链接]

上一主题 下一主题
离线blesser
 
只看楼主 倒序阅读 楼主  发表于: 2010-04-04
— 本帖被 XChinux 从 General Qt Programming 移动到本区(2011-01-02) —
QT版本是qt4.6,功能是计算当前目录下文件夹数量
重复调用第三次以后出现Segmentation fault
怎么都找不出问题
int Dir::countDir(QModelIndex index)
{
       int dirNum=0;
       int i=0;
       QModelIndex modIndex = index.sibling(i,1);
       bool b = model->isDir(modIndex);
       while(b)
       {
           modIndex = index.sibling(i,1);
           b = model->isDir(modIndex);
          dirNum++;
           i++;
       }
        return (dirNum-1);
}

出错是在循环结束以后,return之前
谢谢大家
[ 此帖被blesser在2010-04-05 11:09重新编辑 ]
离线yangfanxing
只看该作者 1楼 发表于: 2010-04-04
model undefined?

why not qDebug() << out the name of the dirs? to check your result.


by the way, if there is 0 dir & b = false & "while" won't excute,so return what then?
PHPWind好恶心。。。不想看这种界面。。。
离线blesser
只看该作者 2楼 发表于: 2010-04-05
Re:请教以下关于QDirModel代码的问题
引用第1楼yangfanxing于2010-04-04 23:07发表的  :
model undefined?
why not qDebug() << out the name of the dirs? to check your result.
.......


太谢谢楼上了

我找到问题所在了
model已经定义过,不是这个问题
qDebug我也用过 为了帖论坛上代码简洁删掉了
返回逻辑有点问题 但是没有文件夹不是问题
如果没有第一个文件才是问题 这样就直接出现数组越界

  
[ 此帖被blesser在2010-04-05 11:09重新编辑 ]
快速回复
限100 字节
 
上一个 下一个