Results 1 to 3 of 3

Thread: QTreeWidget Saving items

  1. #1
    Join Date
    Feb 2013
    Posts
    71
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Platforms
    Windows

    Default Re: QTreeWidget Saving items

    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
    Qt Code:
    1. //DIALOG that is adding items
    2. times.clear(); //clearing so it doesnt display anything in the textEdits when I open the dialog.
    3. for(int i = 0; i<24;i++){
    4. if(!addedTimes[i].isEmpty()){
    5. times << addedTimes[i];
    6. } else {
    7. times << "No Food";
    8. }
    9. }
    10.  
    11. //MAINWINDOW that I want to save the items when i close
    12. for(int i = 0; i<allDates.size();i++){
    13. for(int j = 0; j<24; j++){
    14. allTimes << times[j];
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 
    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
    Qt Code:
    1. allTimes << times;
    To copy to clipboard, switch view to plain text mode 
    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
    Last edited by giblit; 29th March 2013 at 06:38.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QTreeWidget Saving items

    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?
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Feb 2013
    Posts
    71
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Platforms
    Windows

    Default Re: QTreeWidget Saving items

    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:
    Qt Code:
    1. for(int i = 0; i<allDates.size(); i++){
    2. out << allDates[i];
    3. for(int j = 0; j<24; j++){
    4. out << allTimes[j];
    5. }
    6. }
    To copy to clipboard, switch view to plain text mode 
    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
    Qt Code:
    1. out << allTimes[j+(24*i)];
    To copy to clipboard, switch view to plain text mode 
    thanks for help though.

Similar Threads

  1. removing items QTreeWidget
    By Mystical Groovy in forum Qt Programming
    Replies: 3
    Last Post: 25th March 2015, 21:58
  2. QTreeWidget, i cant see the items
    By clepto in forum Qt Programming
    Replies: 1
    Last Post: 20th May 2012, 11:15
  3. Saving QGraphics Scene items
    By chaltier in forum Qt Programming
    Replies: 1
    Last Post: 3rd April 2012, 06:35
  4. The order of items in QTreeWidget
    By KK in forum Qt Programming
    Replies: 4
    Last Post: 27th February 2009, 04:54
  5. Saving/Restoring columns order of QTreeWidget
    By mchara in forum Qt Programming
    Replies: 1
    Last Post: 10th October 2007, 08:43

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.