2012-03-07 12 views
0

テキストファイルから文字列(データ)を読み取り、そのデータをQDoubleSpinBoxに書きたいとします。したがって、私が使用:テキストファイルの値を読み取り、その値をQDoubleSpinBoxに書き込む

void GUIsubclassKuehniGUI::LoadDirectory() 
    { 
     QString loadedDirectory = QFileDialog::getExistingDirectory(this, 
                "/home",tr("Create Directory"), 
                QFileDialog::DontResolveSymlinks); 
     ui.PathDirectory -> setText(loadedDirectory); 

     QFileInfo GeoDat1 = loadedDirectory + "/1_geo.m4"; 
     QFileInfo GeoDat2 = loadedDirectory + "/2_geo.m4";   
     QString Value; 

     if (GeoDat1.exists() == true) 
     { 
      QFile GEO (loadedDirectory + "/1_geo.m4"); 

      if(GEO.open(QIODevice::ReadOnly | QIODevice::Text))  
      { 
       QTextStream Stream (&GEO); 
       QString Text; 
       do 
       { 
        Text = Stream.readLine(); 

        QString startWith = "start"; 
        QString endWith = "stop" ;          
        int start = Text.indexOf(startWith, 0, Qt::CaseInsensitive); 
        int end = Text.indexOf(endWith, Qt::CaseInsensitive);   

        if (start != -1)            
         Value = Text.mid(start + startWith.length(), end - (start + startWith.length())); 

qDebug() << Value << (start + startWith.length()) << (end - (start + startWith.length())); 


        double ValueNumber = Value.toDouble(); 
        ValueNumber = ui.ValueQDoubleSpinBox->value(); 
       } 
       while(!Text.isNull()); 
       GEO.close(); 
      } 
     } 
     else if (GeoDat2.exists() == true) 
     { 
      ... 
     } 
    } 

をコンパイルする場合、私は何のエラーメッセージが出ていないが、私はQStringの「バリュー」はメソッド「QStringの::のindexOf」との「QStringの::半ば」で検索LoadDirectoryメソッドを使用する場合QFileInfo :: exists()でプルーフされたファイル "/1_geo.m4"はQDoubleSpinBox "ValueQDoubleSpinBox"に書き込まれません。誰かがそれがなぜ機能していないのか教えてもらえますか?挨拶は

答えて

3

私見次の行:

double ValueNumber = Value.toDouble(); 
ValueNumber = ui.ValueQDoubleSpinBox->value(); // get value from spinbox 

に変更する必要があります。

double ValueNumber = Value.toDouble(); 
ui.ValueQDoubleSpinBox->setValue(ValueNumber); // set value of spinbox 

詳細:http://qt-project.org/doc/qt-4.8/qdoublespinbox.html#value-prop

+0

うんあなたは正しいです - それは今正常に動作します。 :D – Streight

関連する問題