2017-06-14 5 views
0

Ich habe versucht, QSettings zu verwenden und schrieb einen kleinen Test.QSettings findet INI-Datei aber gibt kein Ergebnis

if(QFile("C:/Users/test/network.ini").exists()){ 
    QSettings settings("C:/Users/test/network.ini", QSettings::IniFormat); 
    settings.sync(); 
    settings.beginGroup("Network"); 
    settings.setValue("Port",9999); 
    settings.endGroup(); 
    settings.sync(); 
    settings.beginGroup("Network"); 
    int port = settings.value("Port").toInt(); 
    settings.endGroup(); 
    settings.sync(); 
    qDebug() << port; 
    return port; 
} 

Meine Ini-Datei sieht wie folgt aus:

[Network] 
Port=4444 

Der Dateipfad korrekt ist, aber ich bekomme immer noch keine Ergebnisse. Irgendwelche Ideen?

Antwort

-1

Der Fehler durch die qsettings.h in Qt 5.4.2

Die ursprünglichen Code war, verursacht wurde:

enum Format { 
    IniFormat, 
    IniFormat, 

    InvalidFormat = 16, 
    CustomFormat1, 
    CustomFormat2, 
    CustomFormat3, 
    CustomFormat4, 
    CustomFormat5, 
    CustomFormat6, 
    CustomFormat7, 
    CustomFormat8, 
    CustomFormat9, 
    CustomFormat10, 
    CustomFormat11, 
    CustomFormat12, 
    CustomFormat13, 
    CustomFormat14, 
    CustomFormat15, 
    CustomFormat16 
}; 

Nachdem ich wechselte er nach

enum Format { 
    NativeFormat, 
    IniFormat, 

    InvalidFormat = 16, 
    CustomFormat1, 
    CustomFormat2, 
    CustomFormat3, 
    CustomFormat4, 
    CustomFormat5, 
    CustomFormat6, 
    CustomFormat7, 
    CustomFormat8, 
    CustomFormat9, 
    CustomFormat10, 
    CustomFormat11, 
    CustomFormat12, 
    CustomFormat13, 
    CustomFormat14, 
    CustomFormat15, 
    CustomFormat16 
}; 

alles hat gut funktioniert.

+1

Ich weiß nicht, was Sie tun, aber es scheint nicht richtig. Der von Ihnen angegebene Code würde nicht einmal kompiliert. –

Verwandte Themen