Results 1 to 5 of 5

Thread: How to query data by id in a text file

  1. #1
    Join Date
    Aug 2008
    Posts
    11
    Thanks
    1

    Post How to query data by id in a text file

    Hi,all
    I want to save the data in my MDI application, I want the data save as follows
    subwindow1_id subwindow1data
    subwindow2_id subwindow1data
    .......
    . so I can restore one subwindow data only by the subwindow_id
    but I don't know how to do that with qt .
    any idea ,thanks.

  2. #2
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    4
    Thanked 140 Times in 132 Posts

    Default Re: How to query data by id in a text file

    The simplest way would be to use QSettings to store your data in the .ini file (using QSettings::IniFormat).

    Example:
    Qt Code:
    1. QSettings settings("mysavefile.ini", QSettings::IniFormat);
    2. settings.setValue("subwindow1_id", QString("subwindow1data"));
    To copy to clipboard, switch view to plain text mode 
    the value is a QVariant so you can store almost anything.
    reading:
    Qt Code:
    1. QSettings settings("mysavefile.ini", QSettings::IniFormat);
    2. QString str = settings.value("subwindow1_id").toString();
    To copy to clipboard, switch view to plain text mode 
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  3. #3
    Join Date
    Aug 2008
    Posts
    11
    Thanks
    1

    Default Re: How to query data by id in a text file

    but my data which is a QString in each mdisubwindowdata may be long ,is it suitable to use the QSettings

  4. #4
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    4
    Thanked 140 Times in 132 Posts

    Default Re: How to query data by id in a text file

    I don't know if there is any limit, and don't know what "long" means exactly :] is it 100 characters? 100 lines? 100 pages? If there are a lot of data, maybe you should save them as XML file, maybe even in some more complicate structure or something? you can also store data in text file in the way you want and use the QString methods and/or QRegExps to read the data. But I would trye QSettings first, cause it looks like the simplest solution.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: How to query data by id in a text file

    If you have more windows with the same parameters you also can use QSettings::beginGroup() instead of adding a index to the name. As a beginner I'd use QSetting at first. If you mere experienced you could use XML if it is really necessary.

Similar Threads

  1. Problem pasting text into a QTextEdit
    By Spockmeat in forum Qt Programming
    Replies: 8
    Last Post: 14th March 2009, 15:36
  2. Editable text in QGraphicsView
    By wysota in forum Qt Programming
    Replies: 8
    Last Post: 24th February 2007, 16:30
  3. Replies: 2
    Last Post: 17th November 2006, 12:25
  4. tricks when designing project file formats?
    By pir in forum General Programming
    Replies: 10
    Last Post: 21st July 2006, 14:08
  5. Replies: 3
    Last Post: 23rd June 2006, 18:46

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
  •  
Qt is a trademark of The Qt Company.