@alistair
Not familiar with app in android but still there are different ways in general for saving combo box data.One easier or simpler way is to write it to XML file and read it when application starts.
@alistair
Not familiar with app in android but still there are different ways in general for saving combo box data.One easier or simpler way is to write it to XML file and read it when application starts.
alistair (28th August 2015)
Or write into a QSettings object
Cheers,
_
alistair (28th August 2015)
Thank you for your help but I think I might need a bit more. I tried using QSettings but I could figure out how to get that working at all lol. I have been trying just writing the entries to a .txt file and reading that in but nothing is functioning. Below is my code:
Trying to read entries from .txt file into combo box: (.txt file is one word per line)
Qt Code:
{ while (!in.atEnd()) { ui->pic_cbox->addItem(entry); entry = in.readLine(); } file.close(); }To copy to clipboard, switch view to plain text mode
Trying to write value to text file:
Qt Code:
{ stream << new_entry << endl; // file.seek(0); // file.write(new_entry+"\n"); file.close(); }To copy to clipboard, switch view to plain text mode
I have tried every possible configuration I can think of for both two sections of code and still no result. The writing section does not append but just writes over existing text instead. The reading section just does not populate the combo boxes.
Does anyone know what I'm doing wrong?
Thank you for all of your help and time!!![]()
Last edited by alistair; 28th August 2015 at 04:12.
For writing, you could try to seek to the end before appending, or writing all entries.
For reading you need to fix your loop condition. Right now it won't append the last line (stream at end after reading last line).
Cheers,
_
alistair (8th September 2015)
For writing, it's still overwriting the text at the start of the file for some reason. Code below:
Qt Code:
{ qint64 fileSize = file.size(); file.seek(fileSize()); stream << new_entry << endl; // file.write(new_entry+"\n"); file.close(); }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:
{ while (!(in.atEnd())) { ui->pic_cbox->addItem(entry); entry = in.readLine(); } ui->pic_cbox->addItem(entry); file.close(); }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.
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()?
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,
_
alistair (8th September 2015)
You could also store them using a sqlite.
alistair (8th September 2015)
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!
Bookmarks