Results 1 to 10 of 10

Thread: (Solved) Reading value from INI

  1. #1
    Join Date
    Nov 2009
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default (Solved) Reading value from INI

    Hello,

    Just starting with QT and now have a little problem and don't have a solution:

    A INI-file have the next value: "123,4 Ab" and I want this value in a QLabel.
    Because of the "," it is not possible, how can I handle this?

    Qt Code:
    1. QSettings settings ("log.ini", QSettings::IniFormat);
    2. settings.beginGroup("group");
    3. QString ruuun = settings.value("value", "Nothing").toString(); // value set in ruuun
    4. ui->settings->setText(ruuun); // Nothing displayed because of the ","
    To copy to clipboard, switch view to plain text mode 
    Last edited by WijbeCT; 21st November 2009 at 15:42. Reason: updated contents

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Reading value from INI

    The comma should have nothing to do with this. How does your ini file look like exactly? What is the exact (compilable) code to reproduce the problem?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Nov 2009
    Posts
    39
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Reading value from INI

    i don't know a good solution, but i know one...

    you can read the number in two times with

    Qt Code:
    1. a=line.section(",",0,0).toInt()
    2. b=line.section(",",1,1).toInt()
    3.  
    4. a = a + b/10
    To copy to clipboard, switch view to plain text mode 

    this is only an idea, you should check how many numbers after the symbol , and divide it those times by 10.

    If you dont find any other solution... try this xD

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Reading value from INI

    But he wants it as text, why should he convert it back and forth from integers?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Nov 2009
    Posts
    39
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Reading value from INI

    ohhh i missed that part!!

    then... i cant see the problem there.

  6. #6
    Join Date
    Nov 2009
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Reading value from INI

    The comma should have nothing to do with this. How does your ini file look like exactly? What is the exact (compilable) code to reproduce the problem?
    I have tested the value by chancing the "," in "." and the value is displaying, rechancing in a "," and the value is not displaying....
    Qt Code:
    1. INI:
    2. [file]
    3. run=Woensdag 18 september 2009
    4. cleaning=158,9 Mb verwijderd
    5.  
    6. The code is the "same" as the snippet (only with the value of run and some text).
    To copy to clipboard, switch view to plain text mode 

    Is this not to reproduce(?), after a restart from my computer, for me the problem is the same! I'm working in Qt Creator, maybe that's the reason
    Last edited by WijbeCT; 21st November 2009 at 12:58. Reason: updated contents

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Reading value from INI

    Without quotes the value is treated as a list of strings. Either wrap the value in quotes or convert the variant to a string list.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. The following user says thank you to wysota for this useful post:

    WijbeCT (21st November 2009)

  9. #8
    Join Date
    Nov 2009
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Smile Re: (Solved) Reading value from INI

    Because of the comma in the value (Qt wants to) handle this as a StringList:

    Qt Code:
    1. QString ruuun = settings.value("value", "Nothing").toString(); // value set in ruuun
    To copy to clipboard, switch view to plain text mode 

    chanced in:

    Qt Code:
    1. QStringList ruuun = settings.value("value", "Nothing").toStringList();
    To copy to clipboard, switch view to plain text mode 

    after that, replaced the ",".

    Thanks to "wysota" for showing me this way.

  10. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: (Solved) Reading value from INI

    Quote Originally Posted by WijbeCT View Post
    Thanks to "wysota" for showing me this way.
    You don't have to put my name in quotes, there is no comma in it
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #10
    Join Date
    Nov 2009
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: (Solved) Reading value from INI

    You don't have to put my name in quotes, there is no comma in it
    Now I'm sure I can read you "as is".

Similar Threads

  1. How to Compile VTKDesigner2 with Qt?
    By alfredoaal in forum Newbie
    Replies: 0
    Last Post: 5th September 2008, 05:34
  2. Socket Reading Advice
    By tntcoda in forum Qt Programming
    Replies: 3
    Last Post: 4th July 2008, 11:26
  3. problem with reading text files
    By Axsis in forum Newbie
    Replies: 1
    Last Post: 25th April 2008, 12:29
  4. QTextStream loses position while reading file
    By bjh in forum Qt Programming
    Replies: 2
    Last Post: 13th February 2008, 15:47
  5. QWT 5, QT3, SuSE 10.2. Crash and burn
    By DrMcCleod in forum Qwt
    Replies: 8
    Last Post: 7th September 2007, 20:53

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.