C++ 读取文本文件的值并将该值写入QDoubleSpinBox

C++ 读取文本文件的值并将该值写入QDoubleSpinBox,c++,qt,qstring,qspinbox,C++,Qt,Qstring,Qspinbox,我想从文本文件中读取字符串(数据),然后将数据写入QDoubleSpinBox。因此,我使用: void GUIsubclassKuehniGUI::LoadDirectory() { QString loadedDirectory = QFileDialog::getExistingDirectory(this, "/home",tr("Create Direc

我想从文本文件中读取字符串(数据),然后将数据写入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)
       {
           ...
       }
   }
void gui子类kuehnigui::LoadDirectory()
{
QString loadedDirectory=QFileDialog::getExistingDirectory(此,
“/home”,tr(“创建目录”),
QFileDialog::DontResolveSymlinks);
ui.PathDirectory->setText(loadedDirectory);
QFileInfo GeoDat1=loadedDirectory+“/1_geo.m4”;
QFileInfo GeoDat2=loadedDirectory+“/2_geo.m4”;
QString值;
if(GeoDat1.exists()==true)
{
QFile GEO(loadedDirectory+“/1_GEO.m4”);
if(GEO.open(QIODevice::ReadOnly | QIODevice::Text))
{
QTextStream(和GEO);
QString文本;
做
{
Text=Stream.readLine();
QString startWith=“开始”;
QString endWith=“停止”;
int start=Text.indexOf(startWith,0,Qt::不区分大小写);
int end=Text.indexOf(endWith,Qt::case不区分大小写);
如果(开始!=-1)
Value=Text.mid(start+startWith.length(),end-(start+startWith.length());

qDebug()IMHO以下行:

double ValueNumber = Value.toDouble();
ValueNumber = ui.ValueQDoubleSpinBox->value(); // get value from spinbox
必须更改为:

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

详细信息:

请查看以下行:

double ValueNumber = Value.toDouble();
ValueNumber = ui.ValueQDoubleSpinBox->value(); // get value from spinbox
必须更改为:

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