Results 1 to 5 of 5

Thread: Issue with Qsettings

  1. #1
    Join Date
    Jul 2015
    Posts
    3
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Issue with Qsettings

    Hi,

    I have a problem that I can't find the ini file and it seems that even the default settings are not set.
    The declaration:

    Qt Code:
    1. QSettings *p_projsettings;
    To copy to clipboard, switch view to plain text mode 

    After it I expect the File created

    Qt Code:
    1. p_projsettings = new QSettings("c:temp\MySoft\DCP_MON_INI.ini", QSettings::IniFormat);
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. defaultvalues();
    2. p_projsettings->sync();
    3. if(p_projsettings->status()==QSettings::NoError)
    4. {
    5. retval=false;
    6. }
    7. else
    8. {
    9. retval=true;
    10. }
    11. qDebug() << "Status ProjSettings:" << retval;
    12. return (retval);
    To copy to clipboard, switch view to plain text mode 

    The status is alway false

    Qt Code:
    1. void INI_FILE::defaultvalues()
    2. {
    3. p_projsettings->value("BAUD","230400");
    4. p_projsettings->value("PORT","COM3");
    5. p_projsettings->value("PARITY","NONE");
    6. p_projsettings->value("DATABIT","8");
    7. p_projsettings->value("STOPBIT","1");
    8. p_projsettings->value("FLOWCONTROL","FLOW_OFF");
    9. p_projsettings->value("TIMEOUT","150");
    10. // qDebug("projsettings BAUD",projsettings->value("BAUD"));
    11. qDebug() << "projsettings BAUD:" << p_projsettings->value("BAUD").toString();
    12. p_projsettings->sync();
    13. }
    To copy to clipboard, switch view to plain text mode 

    Could anybody please tell me what is wrong?

    Thanks!

  2. #2
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    120
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Issue with Qsettings

    Hello,

    p_projsettings = new QSettings("c:temp\MySoft\DCP_MON_INI.ini", QSettings::IniFormat);
    The path to your ini file does not exist. You use \ in string constant. Better use / for path separator or, if you insist on using \ as path separator, you have to escape the \ in the string constant, i.e. replace each \ in your path by \\, i.e.
    Qt Code:
    1. p_projsettings = new QSettings("c:temp\\MySoft\\DCP_MON_INI.ini", QSettings::IniFormat);
    To copy to clipboard, switch view to plain text mode 

    Best regards
    ars

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Issue with Qsettings

    Quote Originally Posted by MM5 View Post
    Qt Code:
    1. if(p_projsettings->status()==QSettings::NoError)
    2. {
    3. retval=false;
    4. }
    To copy to clipboard, switch view to plain text mode 
    The status is alway false
    that's good, isn't it? false is the value you assign to retval if there are no errors.

    Quote Originally Posted by MM5 View Post
    and it seems that even the default settings are not set.
    Do you set any default values?

    Quote Originally Posted by MM5 View Post
    Qt Code:
    1. void INI_FILE::defaultvalues()
    2. {
    3. p_projsettings->value("BAUD","230400");
    4. p_projsettings->value("PORT","COM3");
    5. p_projsettings->value("PARITY","NONE");
    6. p_projsettings->value("DATABIT","8");
    7. p_projsettings->value("STOPBIT","1");
    8. p_projsettings->value("FLOWCONTROL","FLOW_OFF");
    9. p_projsettings->value("TIMEOUT","150");
    10. // qDebug("projsettings BAUD",projsettings->value("BAUD"));
    11. qDebug() << "projsettings BAUD:" << p_projsettings->value("BAUD").toString();
    12. p_projsettings->sync();
    13. }
    To copy to clipboard, switch view to plain text mode 
    What is the purpose of this method?
    Reading a bunch of keys but not using the read values doesn't strike me as particularily useful.

    Cheers,
    _

  4. #4
    Join Date
    Jul 2015
    Posts
    3
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Issue with Qsettings

    Do you set any default values?


    What is the purpose of this method?
    Reading a bunch of keys but not using the read values doesn't strike me as particularily useful.

    Cheers,
    Thank you for the quick responce!

    So far I remember the value function, it delivers the value out of seetings or if not exist it uses the default... but yes you are right somehow I have to write the settings.
    I'll look into it...

    Thank you very much !
    BR


    Added after 22 minutes:


    Solved :-) Thanks to the replies!

    BR
    MM
    Last edited by MM5; 18th July 2015 at 18:01.

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Issue with Qsettings

    Qt Code:
    1. p_projsettings = new QSettings("c:temp\MySoft\DCP_MON_INI.ini", QSettings::IniFormat);
    To copy to clipboard, switch view to plain text mode 
    Even with the backslashes properly escaped or replaced with forward slashes (as Ars pointed out) this may still be interpreted as a path that is relative to the current directory on drive C:. Perhaps you should say:
    Qt Code:
    1. p_projsettings = new QSettings("c:\\temp\\MySoft\\DCP_MON_INI.ini", QSettings::IniFormat);
    To copy to clipboard, switch view to plain text mode 

  6. The following user says thank you to ChrisW67 for this useful post:

    MM5 (19th July 2015)

Similar Threads

  1. QSettings - Sync issue between two process
    By kartlee in forum Qt Programming
    Replies: 1
    Last Post: 26th August 2011, 22:19
  2. Replies: 1
    Last Post: 14th January 2011, 11:57
  3. QSettings to/from xml
    By hubbobubbo in forum Qt Programming
    Replies: 1
    Last Post: 23rd November 2010, 12:04
  4. Migrate Qt3 QSettings to Qt4 QSettings
    By hvengel in forum Qt Programming
    Replies: 3
    Last Post: 22nd February 2008, 03:21
  5. Qsettings
    By jrideout in forum Qt Programming
    Replies: 11
    Last Post: 29th June 2006, 19:21

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.