0

テキスト ファイルから文字列 (データ) を読み取り、そのデータを 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)
       {
           ...
       }
   }

コンパイル時にエラーメッセージは表示されませんが、メソッド LoadDirectory を使用すると、存在を証明したファイル「/1_geo.m4」のメソッド「QString::indexOf」および「QString::mid」で検索された QString「Value」 with QFileInfo::exists() は QDoubleSpinBox "ValueQDoubleSpinBox" に書き込まれません。なぜ機能しないのか誰か教えてもらえますか?挨拶

4

1 に答える 1

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

于 2012-03-07T14:44:15.653 に答える