• 3811阅读
  • 3回复

关于QFile的问题 [复制链接]

上一主题 下一主题
离线yanjinchen
 
只看楼主 倒序阅读 楼主  发表于: 2009-07-04
我现在想读取文件中的值以初始化按钮上的文本,但是什么也读不出来,执行完下面的语句后,按钮上什么也没有,到底是为什么阿?请大家帮帮忙,多谢
QFile file( "pwd.dat" );
      if (! file.open( IO_ReadOnly ) ) { QMessageBox *mb=new QMessageBox("","The file can't be opened!",QMessageBox::Critical,QMessageBox::Ok,0,0);
     mb->show();    
      }
      
     if ( file.open( IO_ReadOnly ) ) {
        QTextStream stream( &file );
         while ( !stream.atEnd() ) {
        
         password = stream.readLine();}
          
                            
        file.close();
    }

buttonOk->setText(password);
PS:在pwd.dat中已经预存了字符串。字符串我是用键盘输入的,是不是因此不能读取阿?
[ 此帖被yanjinchen在2009-07-04 11:10重新编辑 ]
离线yanjinchen
只看该作者 1楼 发表于: 2009-07-06
为什么可以写进去却读不出来呢?
离线foxyz

只看该作者 2楼 发表于: 2009-07-06
     QString password;
     QFile file( "pwd.dat" );
      if (! file.open( IO_ReadOnly ) ) {
             QMessageBox::warning(NULL, "Warning","The file can't be opened!");
      }
      else
      {
        QTextStream stream( &file );
        stream >> password;
    }

    file.close();
button->setText(password);
离线yanjinchen
只看该作者 3楼 发表于: 2009-07-06
谢谢楼上指点,自己太粗心了呵呵
快速回复
限100 字节
 
上一个 下一个