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 702 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 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?

    JonBJ 1 Reply Last reply
    0
    • L LT-K101

      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?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on 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
      0
      • JonBJ JonB

        @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 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.

        JonBJ 1 Reply Last reply
        0
        • L LT-K101

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

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on 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

          • Login

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