Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. How to update dateEdit from database
Forum Updated to NodeBB v4.3 + New Features

How to update dateEdit from database

Scheduled Pinned Locked Moved Unsolved Qt for Python
4 Posts 2 Posters 698 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.
  • L Offline
    L Offline
    LT-K101
    wrote on 27 Apr 2022, 06:38 last edited by
    #1

    Hi,
    I want to update dateEdit with a date from database but I have this error message. arguments did not match any overloaded call:
    setDate(self, int, int, int): argument 1 has unexpected type 'str'
    . Below is the code I tried.

    dob = self.ui.dateEdit_4.date().setDate(data[10])
    

    where data is my sql query. Please any help on what I'm doing wrong?

    J 1 Reply Last reply 27 Apr 2022, 06:48
    0
    • L LT-K101
      27 Apr 2022, 06:38

      Hi,
      I want to update dateEdit with a date from database but I have this error message. arguments did not match any overloaded call:
      setDate(self, int, int, int): argument 1 has unexpected type 'str'
      . Below is the code I tried.

      dob = self.ui.dateEdit_4.date().setDate(data[10])
      

      where data is my sql query. Please any help on what I'm doing wrong?

      J Online
      J Online
      JonB
      wrote on 27 Apr 2022, 06:48 last edited by JonB
      #2

      @LT-K101 said in How to update dateEdit from database:

      self.ui.dateEdit_4.date().setDate(data[10])

      QDateEdit.date() returns the date in a QDateEdit. You do not use it to set a date! setDate() does that.

      self.ui.dateEdit_4.setDate(data[10])

      But setDate() does not just accept a string, if that is what is coming back from your database (per the error message). (Why is your column for a date returning a string and not a date/datetime? It should be a datetime type column in the database and be returned as a date type in Qt/Python. I don't know what driver/query you are using.)

      You can probably use something like self.ui.dateEdit_4.dateTimeFromText(data[10]) to convert your string to a date to be passed to setDate(). But that depends on the format of the string in data[10] from the database, you may have to use some other method of QDateTime to parse your input string. Or Python has functions for converting strings to dates.

      L 1 Reply Last reply 27 Apr 2022, 07:13
      0
      • J JonB
        27 Apr 2022, 06:48

        @LT-K101 said in How to update dateEdit from database:

        self.ui.dateEdit_4.date().setDate(data[10])

        QDateEdit.date() returns the date in a QDateEdit. You do not use it to set a date! setDate() does that.

        self.ui.dateEdit_4.setDate(data[10])

        But setDate() does not just accept a string, if that is what is coming back from your database (per the error message). (Why is your column for a date returning a string and not a date/datetime? It should be a datetime type column in the database and be returned as a date type in Qt/Python. I don't know what driver/query you are using.)

        You can probably use something like self.ui.dateEdit_4.dateTimeFromText(data[10]) to convert your string to a date to be passed to setDate(). But that depends on the format of the string in data[10] from the database, you may have to use some other method of QDateTime to parse your input string. Or Python has functions for converting strings to dates.

        L Offline
        L Offline
        LT-K101
        wrote on 27 Apr 2022, 07:13 last edited by
        #3

        @JonB The column data type I'm using is TEXT because these are the available data types INTEGER,TEXT,BLOB,REAL and NUMERIC.

        J 1 Reply Last reply 27 Apr 2022, 07:15
        0
        • L LT-K101
          27 Apr 2022, 07:13

          @JonB The column data type I'm using is TEXT because these are the available data types INTEGER,TEXT,BLOB,REAL and NUMERIC.

          J Online
          J Online
          JonB
          wrote on 27 Apr 2022, 07:15 last edited by JonB
          #4

          @LT-K101
          Then the database features are pretty limited. Maybe it allows some sort of SELECT DATE(column) to return a converted date, I don't know. Anyway so you need to turn it into a date if you want to use QDateEdit.setDate(date).

          1 Reply Last reply
          0

          1/4

          27 Apr 2022, 06:38

          • Login

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