PDA

View Full Version : QTreeWidget Saving items



giblit
29th March 2013, 07:38
This is probably an easy fix but I have spent about an hour trying to figure this out....
what am I doing wrong with my allTime QStringList I am pretty sure I am inserting QStringList time x24 inside of it.
but it doesnt even seem to be updating it keeps the same data as the old ones
ps(I can save every other item in my QTreeDialog well on the close and I can save every item including the times when I append it to the text on the add screen. but if I am removing I would rather not append I need to clear the txt file then add everything back in which I can only add like 90% it keeps the times from index 0 for the times.)


here is the code I am using for times/allTimes


//DIALOG that is adding items
times.clear(); //clearing so it doesnt display anything in the textEdits when I open the dialog.
for(int i = 0; i<24;i++){
if(!addedTimes[i].isEmpty()){
times << addedTimes[i];
} else {
times << "No Food";
}
}

//MAINWINDOW that I want to save the items when i close
for(int i = 0; i<allDates.size();i++){
for(int j = 0; j<24; j++){
allTimes << times[j];
}
}

am I not reading in all 24 time QStrings for every date QString I have? because I am saving using that same formula on the add menu and its working fine when im appending.

Added after 6 minutes:

if I put this on the mainWindow


allTimes << times;
instead of the for loop stuff
it crashes instantly adn then doesnt open till I delete the txt file and clean run it.
so it has to be some sort of loop i think to get the 24x QStrings

Santosh Reddy
29th March 2013, 09:51
what am I doing wrong with my allTime QStringList I am pretty sure I am inserting QStringList time x24 inside of it.
but it doesnt even seem to be updating it keeps the same data as the old ones
Are you not missing allTimes.clear()?



it crashes instantly adn then doesnt open till I delete the txt file and clean run it.
so it has to be some sort of loop i think to get the 24x QStrings
Where does it crash?

giblit
29th March 2013, 19:49
after you asking my why it crashed I thought about it for like 10 minutes..then I realized when I was saving the file.......I accidently put this:
for(int i = 0; i<allDates.size(); i++){
out << allDates[i];
for(int j = 0; j<24; j++){
out << allTimes[j];
}
}

and that would mean out allTimes[0] through allTimes[24] allDates.size() times...and I put this code in my add feature but forgot to put it on this one =/
the needed code was
out << allTimes[j+(24*i)];
thanks for help though.