Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to convert Calendar.selectedDate to QDate

How to convert Calendar.selectedDate to QDate

Scheduled Pinned Locked Moved Unsolved General and Desktop
qdate qcalendar
5 Posts 2 Posters 519 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AlainBo
    wrote on last edited by AlainBo
    #1

    Hello,
    I try to convert a date selected by QtQuick.Controls 1.4 calendar to a QDate. My function is:

    void Unlock::setLimitDate(const QString &limitDate)
    {
        QDate date = QDate::fromString(limitDate, "ddd MMM d hh:mm:ss YYYY Z");
        ...
    }
    

    When I enter in the function, limitDate is: "ven. déc. 27 12:00:00 2019 GMT+0100" and created date is invalid.
    I though it could come from the localisation despite the doc says it should work or maybe from the timezone but even if I write:

    QDate date = QDate::fromString("mon. dec. 23 12:00:00 2019", "ddd MMM d hh:mm:ss YYYY");
    

    I cannot get it working. What's wrong?

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Why do you pass it as QString instead a QDate/QDateTime which for sure is provided to you from QtLabs Calendar

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • A Offline
        A Offline
        AlainBo
        wrote on last edited by AlainBo
        #3

        I do not use qtlabs calendar because I wasn't able to instantiate it in Qt Design, I always get "Invalid property name 'x' (M16) (line 117)".
        So I use QtQuick.Controls 1.4 calendar isntead which only provides the date in that format AFAIK.

        A 1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @AlainBo said in How to convert Calendar.selectedDate to QDate:

          which only provides the date in that format AFAIK.

          No: https://doc.qt.io/qt-5/qml-qtquick-controls-calendar.html#selectedDate-prop

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          0
          • A AlainBo

            I do not use qtlabs calendar because I wasn't able to instantiate it in Qt Design, I always get "Invalid property name 'x' (M16) (line 117)".
            So I use QtQuick.Controls 1.4 calendar isntead which only provides the date in that format AFAIK.

            A Offline
            A Offline
            AlainBo
            wrote on last edited by
            #5

            I found my way.

            I don't know where is the doc about calendar.selectedDate but I found what I need in the QtQuickControls 1 - Calendar example.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved