[SOLVED] Empty file on creation - take two
-
Funny - at first I tried creating my own config file manual. But the code I made always ended up creating an empty config file.
I was suggested to use QSettings and I took that approach up.Now I have made a few lines of code and surprise - I end up with an empty config file.
I'm about to give up
Definition:
@ QString configBasePath;
QString configFolderPath;
QString configfilePath;
int defaultIdleTimeout;bool isConfigFile(); int createNewConfigFile(); bool readConfigFile(); bool writeConfigFile(); bool myDEBUG;@
Methods:
@QSaverControlCenter::QSaverControlCenter(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::QSaverControlCenter)
{QString homeLocation = QStandardPaths::locate(QStandardPaths::HomeLocation, QString(), QStandardPaths::LocateDirectory); this->configBasePath = homeLocation+".config/"; this->configFolderPath = homeLocation+".config/QSaver/"; this->configfilePath = homeLocation+".config/QSaver/QSaver.conf"; this->myDEBUG = true; bool test = this->isConfigFile(); QSettings settings(this->configfilePath,QSettings::NativeFormat); if (test == false) { if(this->myDEBUG) { qDebug() << "Constructor - can not find configuration file"; } //create new settings file and establish default timeout this->defaultIdleTimeout = 5; settings.setValue("timeout",this->defaultIdleTimeout); } else { this->defaultIdleTimeout = settings.value("timeout").toInt(); if (this->myDEBUG) { // Read settings qDebug() << "Value : " << this->defaultIdleTimeout; } } ui->setupUi(this);
}@
@bool QSaverControlCenter::isConfigFile(){
QFileInfo myFile(this->configfilePath);
if(myFile.exists() == false)
{
if (this->myDEBUG){qDebug() << "QSCC::isConfigFile - Config file do not exist";}
return false;
}
else
{
if (this->myDEBUG){qDebug() << "QSCC::isConfigFile - Config file exists";}
return true;
}
}@ -
Hi,
On which OS are you running this code ? Also is there any other code in the program which is overwriting the created file ?