Results 1 to 18 of 18

Thread: QDateEdit and date returned

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2008
    Location
    Rome, Italy
    Posts
    95
    Thanks
    19
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default QDateEdit and date returned

    Hi to All,
    I'm using a QDateEdit widget to edit date values from a database, so I display date values as "dd/MM/yyyy" (settting displayFormat). When I finish to update the record the QDateEdit widget returns "yyyy-MM-dd" formtat. Is there a way to change the return value?
    Thanks.

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDateEdit and date returned

    try to set display format using setDisplayFormat.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Jun 2008
    Location
    Rome, Italy
    Posts
    95
    Thanks
    19
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDateEdit and date returned

    The method setDisplayFormat doesn't work, QDateEdit returns the same formatted value "dd-MM-yyyy"!!!

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDateEdit and date returned

    QDateEdit returns QDate, if you need to convert date to string then use QDate::toString with format==dd/MM/yyyy.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  5. #5
    Join Date
    Jun 2008
    Location
    Rome, Italy
    Posts
    95
    Thanks
    19
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDateEdit and date returned

    I'm trying to set the format value returned because QDateEdit widget is mapped to a QSqlTableModel!!!

  6. #6
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDateEdit and date returned

    I don't understand what do you want.
    can you attach compilable example?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  7. #7
    Join Date
    Jun 2008
    Location
    Rome, Italy
    Posts
    95
    Thanks
    19
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDateEdit and date returned

    The following code show you how I'm using the QDateEdit widget:

    Qt Code:
    1. frmEntUsc_AME::frmEntUsc_AME(QSqlRelationalTableModel *model,
    2. const int &isItNew, QWidget *parent) : QDialog(parent)
    3. {
    4. ui.setupUi(this);
    5. this->setWindowFlags(Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
    6. this->setAttribute(Qt::WA_DeleteOnClose);
    7.  
    8. modelAME = new QSqlTableModel(this);
    9. modelAME = model;
    10.  
    11. modelAME->database().transaction();
    12.  
    13. if (isItNew < 0)
    14. {
    15. id = modelAME->rowCount();
    16. modelAME->insertRow(id);
    17. ui.dedData->setDate(QDate::currentDate());
    18. }
    19. else
    20. {
    21. id = isItNew;
    22. }
    23.  
    24. ui.dedData->setDisplayFormat("dd/MM/yyyy"); //QDateEdit widget
    25.  
    26. mapper = new QDataWidgetMapper(this);
    27. mapper->setModel(modelAME);
    28. mapper->setItemDelegate(new QSqlRelationalDelegate(this));
    29. mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
    30. //...
    31. //...
    32. mapper->addMapping(ui.dedData, 9); // the QDateEdit widget is mapped to a date field
    33. mapper->setCurrentIndex(id);
    34.  
    35. connect(ui.btnAnnulla, SIGNAL(clicked()), this, SLOT(revert()));
    36. connect(ui.btnOk, SIGNAL(clicked()), this, SLOT(submit()));
    37.  
    38. qDebug() << "frmEntUsc_AME Loaded!";
    39. }
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDateEdit and date returned

    which date format do you use in a database?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  9. #9
    Join Date
    Jun 2008
    Location
    Rome, Italy
    Posts
    95
    Thanks
    19
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDateEdit and date returned

    I'm using a SQLITE database, the field is declared as TEXT!

  10. #10
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDateEdit and date returned

    why? why is not date?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  11. #11
    Join Date
    Jun 2008
    Location
    Rome, Italy
    Posts
    95
    Thanks
    19
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDateEdit and date returned

    As you know, SQLITE allow only few datatype :
    • NULL
    • INTEGER
    • REAL
    • TEXT
    • BLOB

Similar Threads

  1. How to put empty value in QDateEdit?
    By sawerset in forum Qt Programming
    Replies: 5
    Last Post: 14th October 2019, 21:06
  2. QDateTimeEdit (QTimeEdit, QDateEdit) invalid input
    By Kumosan in forum Qt Programming
    Replies: 10
    Last Post: 15th June 2012, 12:21
  3. QDateEdit and empty date
    By vieraci in forum Qt Programming
    Replies: 1
    Last Post: 3rd November 2007, 16:19
  4. Replies: 0
    Last Post: 2nd May 2007, 10:53
  5. Problem with receiving events from QDateEdit
    By gunhelstr in forum Qt Programming
    Replies: 4
    Last Post: 20th April 2006, 11:21

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.