Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Empty file on creation - take two
QtWS25 Last Chance

[SOLVED] Empty file on creation - take two

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    flywheel
    wrote on last edited by
    #1

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

    Live long and prosper...

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

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

      157

      1 Reply Last reply
      0
      • F Offline
        F Offline
        flywheel
        wrote on last edited by
        #3

        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.

        Live long and prosper...

        1 Reply Last reply
        0
        • F Offline
          F Offline
          flywheel
          wrote on last edited by
          #4

          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.

          Live long and prosper...

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved