Results 1 to 8 of 8

Thread: How to dispaly date in format dd/mm/yyyy using QSqlTableModel

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2007
    Posts
    9
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to dispaly date in format dd/mm/yyyy using QSqlTableModel

    Hi,
    I am using Qt 4.2.3.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to dispaly date in format dd/mm/yyyy using QSqlTableModel

    Quote Originally Posted by bala View Post
    I am using Qt 4.2.3.
    Alright, so you might want to try the approach shown in our wiki. Start with subclassing QSqlTableModel and reimplementing data(). First, you'll get the actual value from base class. Then, you do some adjustments when appropriate, when certain conditions are met:
    Qt Code:
    1. QVariant MySqlTableModel::data(const QModelIndex& index, int role) const
    2. {
    3. if (!index.isValid())
    4. return QModelIndex();
    5.  
    6. // get the actual value from base class
    7. QVariant value = QSqlTableModel::data(index, role);
    8.  
    9. // do adjustments if necessary
    10. if (role == Qt::DisplayRole && index.column() == theColumnWhichContainsDates)
    11. {
    12. QDate date = value.toDate();
    13. value = date.toString("dd/MM/yyyy");
    14. }
    15.  
    16. return value;
    17. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. #3
    Join Date
    Nov 2007
    Posts
    9
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to dispaly date in format dd/mm/yyyy using QSqlTableModel

    Hi,
    I have implemented the code.
    It was compiling fine but while
    running it shows segmentation fault.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to dispaly date in format dd/mm/yyyy using QSqlTableModel

    Compile the app in debug mode ("qmake -config debug"), run it via debugger ("gdb ./app"), make it crash, and paste backtrace ("bt") here.
    J-P Nurmi

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.