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. QDataWidgetMapper and formatting date/time
Forum Updated to NodeBB v4.3 + New Features

QDataWidgetMapper and formatting date/time

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 3.7k Views 1 Watching
  • 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.
  • S Offline
    S Offline
    scarleton
    wrote on last edited by
    #1

    There is currently an "order date" column table in a SQLite DB which holds the string "2011-08-21", when that column is mapped (via QDataWidgetMapper) to a QDateEdit, it is not parsing the string into a date correctly. Is there some way to control the formatting in this situation?

    Side note, if it matters: In the next 6-month the DB is going to be converted from SQLite to Firebird.

    Sam

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dangelog
      wrote on last edited by
      #2

      I think the easiest way would be creating a custom QItemDelegate subclass, and override setEditorData and setModelData. In those you can check (qobject_cast) if you're getting/setting data from/to the QDateEdit, and properly convert the string to a QDate or vice-versa.

      Software Engineer
      KDAB (UK) Ltd., a KDAB Group company

      1 Reply Last reply
      0
      • S Offline
        S Offline
        scarleton
        wrote on last edited by
        #3

        Well, I like the idea, but... I don't see setItemDelegate on the QDateEdit widget. How do I set a custom delegate on the QDateEdit?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          scarleton
          wrote on last edited by
          #4

          I get it, I set the delegate on the QDataWidgetMapper.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #5

            Just for the records:
            Unfortunately, SQLite does not provide a native date/time type. It is usually mapped into a string columns (like in your case) or an int or double typed column (usually holding seconds since epoch = 1970-01-01 00:00:00 GMT).

            PS:
            Ah, I see you got that string to date conversion already and just search for the proper way to inject that beast.

            http://www.catb.org/~esr/faqs/smart-questions.html

            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