Results 1 to 7 of 7

Thread: Figuring out what date is more recent than the other?

  1. #1
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Figuring out what date is more recent than the other?

    Hello all.
    I think my problem is quite complex.
    My program saves history of the actions the user did. I like the way it does this, and I wouldn't like to change it, actually.
    The problem is that it takes some filenames from a directory named, e.g.
    Wednesday 03.16.2011 and simply adds them to a treewidget.
    Unfortunately, it adds them in random order, but, what I want is e.g.
    the Tuesday 03.01.2011 to be 1st, then Thursday 03.03.2011 to be second and Sunday 03.20.2011 to be third.
    I have to mention that only the days do count, because I make another parent for another month. So, actually, I have to compare the value between the two dots (03.01.2011) and then do a binary search and figure out how to make the list as I want and then add to the treewidget....


    How can I extract the value I want ?
    I'm thinking making a float a[31]; and adding there as I wish the values I want, but even if I have the values in there as I want e.g.
    a[1]=01
    a[2]=05
    a[3]=13
    a[4]=26 etc
    How can I now which values matches with each item in order to place them correctly?
    When you 're trying to help somebody in the newbie section, don't forget that he is a newbie. Be specific and give examples.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Figuring out what date is more recent than the other?

    How do you add items to the tree?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Figuring out what date is more recent than the other?

    I'm making a parent (which is the month) and..
    parnt->addChild(child1);
    When you 're trying to help somebody in the newbie section, don't forget that he is a newbie. Be specific and give examples.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Figuring out what date is more recent than the other?

    So why don't you just add the item in the proper place using QTreeWidgetItem::insertChild() instead of adding it at the end of the list? You don't need to parse anything, you can store the date as a value for a custom role in the item.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    hakermania (20th March 2011)

  6. #5
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Figuring out what date is more recent than the other?

    Also, note that you can impose a strict ordering on dates with the information you already have if you order them by YYYYMMDD, with single digit values left-padded with zeros. This format is monotonically increasing for all dates.

    Or, if your dates are guaranteed to lie within the Unix epoch (> ~1970?) you can simply use a system or Qt routine to convert the calendar date into a Unix-style timestamp, which will again be a monotonically increasing series of integer values.

    Either way, you can trivially order your filenames by implementing a comparison function and applying a sort routine.

  7. The following user says thank you to SixDegrees for this useful post:

    hakermania (20th March 2011)

  8. #6
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Figuring out what date is more recent than the other?

    Build yourself a function int extractDay(QString date). Use a (static) QRegExp (something like \d+\.(\d+)\.\d+ ) and its capturing text functionality to extract the relevant string and convert that to int with QString::toInt().

    When inserting, walk through the already inserted siblings and move forward only when the extracted day is greater than the one of the other item.. This results in a bubble sort.

    Let me know if you need more details,

    HIH

    Joh

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

    hakermania (20th March 2011)

  10. #7
    Join Date
    Jul 2010
    Location
    /home/hakermania/
    Posts
    233
    Thanks
    129
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Figuring out what date is more recent than the other?

    Thx to all, I'll try all the solutions you gave, and if I don't make it, I'll post back
    When you 're trying to help somebody in the newbie section, don't forget that he is a newbie. Be specific and give examples.

Similar Threads

  1. Need help figuring out how to paint graphicsRectItems correctly
    By lightning2911 in forum Qt Programming
    Replies: 1
    Last Post: 6th May 2010, 08:39
  2. Recent Project
    By bismitapadhy in forum Qt Programming
    Replies: 3
    Last Post: 31st May 2009, 09:24
  3. figuring out who's holding up
    By baray98 in forum General Programming
    Replies: 4
    Last Post: 7th December 2007, 19:29
  4. Recent changes in QT 4?
    By Michiel in forum Qt Programming
    Replies: 3
    Last Post: 18th February 2007, 13:29
  5. How to default Date-Edit Widget to system date
    By JohnToddSr in forum Qt Tools
    Replies: 4
    Last Post: 17th January 2007, 20:18

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.