[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&#41;;
    

    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;
    }
    }@


  • Moderators

    Hi,

    On which OS are you running this code ? Also is there any other code in the program which is overwriting the created file ?



  • openSUSE Linux 13.1 (Linux 3.11.10-7-default x86_64) and thereby the Linux 64-bit SDK.
    No, the other methods are empty.



  • Funny - Just took on advice from a 15 year old Windows user - go reinstall the damn thing and don't forget to delete the old configfiles - and I did reinstall the SDK - and behold the code works now.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.