Results 1 to 10 of 10

Thread: Saving values from Qlineedit and qcombobox?

  1. #1
    Join Date
    May 2012
    Posts
    33
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Saving values from Qlineedit and qcombobox?

    I have a GUI, which have several text fields and some combobox. I want to give user a privilege to save these fields as a file and next time when he opens , he should have the option to select that file and all the values he set last time should reflect in those textboxes and combobox? how to do it.
    Thanks in advance

  2. #2
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: Saving values from Qlineedit and qcombobox?

    Take a look at QApplication::saveState, maybe it helps. If not you may manually save items and current indices to the .ini file that you can load next time the application starts.

  3. The following user says thank you to mentalmushroom for this useful post:

    prabhudev (21st May 2012)

  4. #3
    Join Date
    May 2012
    Posts
    33
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Saving values from Qlineedit and qcombobox?

    Thanks mentalmushroom. I am building this application on linux. I am not sure of .ini files in linux. I will look in to Qapplication::saveState. In mean time can you tell how to proceed using .ini files.

  5. #4
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: Saving values from Qlineedit and qcombobox?

    Saying .ini file I meant just an initialization file. It may have any structure or extension suitable for you. The idea was just to store all the content and parameters when you close the app, and when you start it again, read all the content and parameters and fill your controls with the data loaded.

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

    prabhudev (21st May 2012)

  7. #5
    Join Date
    May 2012
    Posts
    33
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Saving values from Qlineedit and qcombobox?

    Thanks...QApplication doesn't help.. Now can you please help how to save in a file and how to read it later..Thanks

  8. #6
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: Saving values from Qlineedit and qcombobox?

    Example how to write data to the file:
    Qt Code:
    1. QFile file("file.dat");
    2. file.open(QIODevice::WriteOnly);
    3. QDataStream out(&file); // we will serialize the data into the file
    4. out << QString("the answer is"); // serialize a string
    5. out << (qint32)42; // serialize an integer
    To copy to clipboard, switch view to plain text mode 

    Read data from the file:
    Qt Code:
    1. QFile file("file.dat");
    2. file.open(QIODevice::ReadOnly);
    3. QDataStream in(&file); // read the data serialized from the file
    4. QString str;
    5. qint32 a;
    6. in >> str >> a; // extract "the answer is" and 42
    To copy to clipboard, switch view to plain text mode 

    There is also QTextStream class that is more convenient for writing/reading text.

  9. The following user says thank you to mentalmushroom for this useful post:

    prabhudev (21st May 2012)

  10. #7
    Join Date
    May 2012
    Posts
    33
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Saving values from Qlineedit and qcombobox?

    I will try and post back

  11. #8
    Join Date
    May 2012
    Location
    Bangalore, India
    Posts
    271
    Thanks
    29
    Thanked 50 Times in 47 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Saving values from Qlineedit and qcombobox?

    Use file handling technique to save the file.
    Use getter method to get the text from the textedit i.e. getText(), and for combo box use getvalue() and save these value to temp and write it into the file through file handling.
    I think you know file handling or you can search through the internet.

  12. The following user says thank you to sonulohani for this useful post:

    prabhudev (21st May 2012)

  13. #9
    Join Date
    May 2012
    Posts
    33
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Saving values from Qlineedit and qcombobox?

    Hey thanks to both of you.

  14. #10
    Join Date
    May 2012
    Posts
    33
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Saving values from Qlineedit and qcombobox?

    Hey need help. how to "save as" for saving the fields.

Similar Threads

  1. Replies: 1
    Last Post: 22nd February 2012, 12:32
  2. How to convert string hex values to its real binary values?
    By AttilaPethe in forum Qt Programming
    Replies: 1
    Last Post: 20th February 2012, 22:47
  3. Replies: 1
    Last Post: 12th October 2010, 22:20
  4. Saving as XML
    By rakkar in forum Newbie
    Replies: 2
    Last Post: 30th October 2009, 17:17
  5. QComboBox values?
    By dbrmik in forum Newbie
    Replies: 8
    Last Post: 9th January 2009, 08:32

Tags for this Thread

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.