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)
{
...
}
}
編譯時我沒有得到任何錯誤信息,但是當我使用的方法LoadDirectory的QString的「價值」與搜索的方法「的QString ::的indexOf」和「的QString ::中旬」文件「/1_geo.m4」存在我用QFileInfo :: exists()驗證的內容沒有寫入QDoubleSpinBox「ValueQDoubleSpinBox」中。有人可以告訴我爲什麼它不起作用嗎?問候
是的,你是正確的 - 現在工作得很好。 :d – Streight 2012-03-07 16:53:25