Results 1 to 14 of 14

Thread: Working with Date type in database applications

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Working with Date type in database applications

    You can overload paint(), check if you should treat any column in a special way, mark it somehow, call original paint() and in drawDisplay check for that mark and act according to it.

    There is no need to rewrite paint() code.

    BTW. A quick solution would be to return the date from the database in a format of your choice, instead of converting it when you display it.

    Anyway, the PROPER solution would be to reimplement the model.

  2. #2
    Join Date
    Jan 2006
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Working with Date type in database applications

    Quote Originally Posted by wysota
    You can overload paint(), check if you should treat any column in a special way, mark it somehow, call original paint() and in drawDisplay check for that mark and act according to it.

    There is no need to rewrite paint() code.

    BTW. A quick solution would be to return the date from the database in a format of your choice, instead of converting it when you display it.

    Anyway, the PROPER solution would be to reimplement the model.
    Yes, it is posible. But looks like hack though.

    As to the model:

    Model returns data in QVariant format.
    In delegate I see:

    QItemDelegate:: paint(...)
    {
    ...
    QString text = model->data(index, Qt:: DisplayRole).toString();
    ...
    }
    in case that data is of DATE type, toString() makes ISODate convertion.

    So, as I've mentioned, model returns data in QVariant format and for the MODEL I think it is a good solution. It is responsibility of VIEW to view data in this or that way.

    So it seems that QItemDelegate:: paint(...) has an ill design.

  3. #3
    Join Date
    Jan 2006
    Posts
    75
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 5 Times in 4 Posts

    Default Re: Working with Date type in database applications

    maybe you can format the date-output using built-in sql function from database first?

    like to_date(), to_string in oracle

  4. #4
    Join Date
    Jan 2006
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Working with Date type in database applications

    Quote Originally Posted by ball
    maybe you can format the date-output using built-in sql function from database first?

    like to_date(), to_string in oracle
    If I still want (and I do!) it to be of DATE type, it will not matter.
    Because QItemDelegate will call model's data(...) method that converts all received from database data to QVariant and then QItemDelegate will call QVariant::toString() -> so again ISODate conversion.

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

    Default Re: Working with Date type in database applications

    Yes, it is a limitation, for sure and there are probably more issues like this, but we have to cope with what we have.

Similar Threads

  1. Compile 4.4.0
    By LordQt in forum Installation and Deployment
    Replies: 18
    Last Post: 29th May 2008, 13:43
  2. dummy question(Error)
    By Masih in forum Qt Programming
    Replies: 12
    Last Post: 19th July 2007, 23:38

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.