Domanda

I want to read a String (Data) out of a text file and write the Data into a QDoubleSpinBox. Therefore I used:

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)
       {
           ...
       }
   }

When compiling I get no error message, but when I use the method LoadDirectory the QString "Value" searched with the methods "QString::indexOf" and "QString::mid" of the file "/1_geo.m4" which existence I proofed with QFileInfo::exists() is not written into the QDoubleSpinBox "ValueQDoubleSpinBox". Can someone tell me why it is not working? greetings

È stato utile?

Soluzione

IMHO the following lines:

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

have to be changed to:

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

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top