Results 1 to 9 of 9

Thread: Saving item to QComboBox on Android

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2015
    Posts
    11
    Thanks
    8
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Saving item to QComboBox on Android

    For writing, it's still overwriting the text at the start of the file for some reason. Code below:
    Qt Code:
    1. QFile file(filename);
    2. if (file.open(QIODevice::ReadWrite | QIODevice::Append | QIODevice::Text))
    3. {
    4. qint64 fileSize = file.size();
    5. file.seek(fileSize());
    6. QTextStream stream(&file);
    7. stream << new_entry << endl;
    8. // file.write(new_entry+"\n");
    9. file.close();
    10. }
    To copy to clipboard, switch view to plain text mode 

    For reading in values, it just doesn't populate the combo box at all. Code below:

    Qt Code:
    1. QFile file(filename);
    2. if (file.open(QIODevice::ReadOnly))
    3. {
    4. QTextStream in(&file);
    5. QString entry = in.readLine();
    6. while (!(in.atEnd()))
    7. {
    8. ui->pic_cbox->addItem(entry);
    9. entry = in.readLine();
    10. }
    11. ui->pic_cbox->addItem(entry);
    12. file.close();
    13. }
    To copy to clipboard, switch view to plain text mode 

    Thank you for your help!
    Last edited by alistair; 1st September 2015 at 02:43.

  2. #2
    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: Saving item to QComboBox on Android

    Quote Originally Posted by alistair View Post
    For writing, it's still overwriting the text at the start of the file for some reason.
    And you have made sure that the value in fileSize is the same value returned by the fileSize() function you are calling there?
    What's the value of pos() after the seek()?

    Quote Originally Posted by alistair View Post
    For reading in values, it just doesn't populate the combo box at all.
    I assume you have verfied that the addItem() calls are processed and the respective "entry" values are what you have been expecting.

    So, since the combobox is populated correctly as verfied by you, maybe it is cleared elsewhere?

    Cheers,
    _

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

    alistair (8th September 2015)

  4. #3
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Saving item to QComboBox on Android

    You could also store them using a sqlite.

  5. The following user says thank you to adutzu89 for this useful post:

    alistair (8th September 2015)

  6. #4
    Join Date
    Jul 2015
    Posts
    11
    Thanks
    8
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Saving item to QComboBox on Android

    Hi,

    I'm sorry but the code I posted is now working and I'm not sure why it wasn't working before. Thanks heaps for everyone's help!

Similar Threads

  1. Replies: 1
    Last Post: 22nd September 2013, 13:40
  2. Saving values from Qlineedit and qcombobox?
    By prabhudev in forum Newbie
    Replies: 9
    Last Post: 23rd May 2012, 05:53
  3. QCheckBox as item of QComboBox
    By Grinchman in forum Newbie
    Replies: 6
    Last Post: 23rd June 2011, 13:44
  4. Replies: 0
    Last Post: 10th March 2011, 11:44
  5. QComboBox and item
    By drow in forum Qt Programming
    Replies: 4
    Last Post: 14th June 2006, 09:04

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