Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qsettings will not read ini when run from Qt Creator.



  • Hello,
    I am targeting an imx6 based device running embedded linux. The target will run my application on powerup. If I let the target power up, then I can read and write from settings.ini file with no problems. I then stop the application via SSH from my development machine and run the application from Qt Creator. When starting the app my QSettings wrapper class can not read any values and will always return the default. However, I can still write to the ini file when run from Qt Creator.

    The ini file has read/write permissions to the root user and read to others. What would stop the reading of values from QSettings when application is launched from Qt Creator? Yet still enable writing.

    Any feedback is much appreciated, thanks,


  • Moderators

    @AndreiS
    how exactly do you set the path to the ini file?
    If you just set the filename it is read from the current working directory (see QDir), which is probably not the same when running from QtCreator. But QtCreator provides an option field to set the remote working directory in the projects RUN settings.



  • There is a wrapper class where the file name is set in the constructor of QSettings. It's a hard coded path where we append onto app.applicationDirPath() . Again, what's strange is that I can write to the file when running from QtCreator. So I can run from QtCreator, make changes to ini, stop application, cycle target power, and the application will pick up the changes. Stop application, launch from QtCreator and changes are lost.

    Thanks,



  • My apologies, this was self induced. Not sure why it was acting that way, but I fixed it. Please delete this topic. Thank you.



  • @AndreiS said in Qsettings will not read ini when run from Qt Creator.:

    Please delete this topic

    No, please mark it as solved, and if possible, please explain a little better what you did to overcome the issue. Thanks.



  • I think this is what the issue was...
    I have a PLC communicating with my device over Modbus TCP. When the application starts it writes several pieces of data over modbus if the PLC is "connected". When I cycle power my target device comes to life before the PLC is "connected" and so it won't try and send the data. And all is well. When I run from QtCreator the PLC is ready, the data is sent, and I was attempting to do the following:

        quint16 value;
        m_settings->setValue(_lowerRatio,value);
    

    However, after this code it appears my _loweRatio key has been removed from the ini. Therefore, no longer available for reading later in the application. I must assume QSettings didn't like the quint16 because this works with an int.



  • @AndreiS
    It would not be good if QSettings removed the key from the INI file if you pass it a quint16 rather than an int.

    From the first post in https://forum.qt.io/topic/35878/qvariant-does-not-support-int8-and-int16 you will see they may be serlialized as 32-bit, I don't know if that could affect your code anywhere, but the key should not get deleted from the INI file.



  • @JonB Perhaps I'm mistaken and a quint16 does not remove the key, however it appeared that way. I moved on by storing my quint16 as an int, as you mentioned, and never looked back. Coincidentally, QSetting appears to be working as intended now. I will try and recreate the scenario (code & HW) and further test the claim that the key was being removed.


Log in to reply