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. Problem with QtDateTime
Forum Update on Monday, May 27th 2025

Problem with QtDateTime

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.1k 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.
  • N Offline
    N Offline
    nanohueso
    wrote on 24 Oct 2013, 19:25 last edited by
    #1

    Hi, im using the Date/Time Edit widget. I want that the widget to start (default date/time) from the current date time of my region ( Buenos Aires) , and i want to modify it and then extract the datetime in to a string , in order to have something like this buffer[15] , where the buffer is composed in something like this

    buffer[0] = YEAR
    buffer[1] = YEAR
    buffer[2]='/'
    buffer[3] = month
    buffer[4]=month
    buffer[5]='/'
    buffer[6]=day
    buffer[7]=day
    buffer[8]=hour
    buffer[9]=hour
    buffer[10]=':'
    buffer[11]=mins
    buffer[12]=mins
    buffer[13]='P' or 'A'
    buffer[14]='M
    buffer(15]='\o'

    ¿How can i make that when i run thee program , the widget starts for the current date time ?
    ¿How can i put in a string the date-time configurated from the widget ?

    QDateTime aux;
    QString auxstr;
    ui->dateTimeEdit_inicial->setDateTime(aux.currentDateTime()); // where do i have to put this code ? in which function?
    note: dateTimeEdit_inicial is the object name of the widget
    then, i have to find someway to pass the information from the widget to the aux ( aux is a QDateTime variable) because then i use aux.toString(auxstr); and then i have the string completed :)
    Also, i need to resize the QString auxstr in order to be capable of containing the whole array of characters , i have to use the member function resize : auxstr.resize( WHAT DO I HAVE TO PUT IN HERE ?? ) ;

    I think thats all .
    Thank you for your time!!

    1 Reply Last reply
    0
    • R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 25 Oct 2013, 06:27 last edited by
      #2

      [quote author="nanohueso" date="1382642732"]
      QDateTime aux;
      QString auxstr;
      ui->dateTimeEdit_inicial->setDateTime(aux.currentDateTime()); // where do i have to put this code ? in which function?
      note: dateTimeEdit_inicial is the object name of the widget
      [/quote]
      probably somewhere in the constructor of your class where you setup "ui". But IIRC QDateTime should have the current time by default?

      [quote author="nanohueso" date="1382642732"]
      then, i have to find someway to pass the information from the widget to the aux ( aux is a QDateTime variable) because then i use aux.toString(auxstr); and then i have the string completed :)
      [/quote]
      just use QDateTime::toString(formatString) and you are good to go.

      [quote author="nanohueso" date="1382642732"]
      Also, i need to resize the QString auxstr in order to be capable of containing the whole array of characters , i have to use the member function resize : auxstr.resize( WHAT DO I HAVE TO PUT IN HERE ?? ) ;
      [/quote]
      No you don't need to do that. Just assign it with "=" and let Qt do the rest for you ;)

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nanohueso
        wrote on 25 Oct 2013, 14:40 last edited by
        #3

        Thank you so much!!!! :) got it!!

        1 Reply Last reply
        0

        2/3

        25 Oct 2013, 06:27

        • Login

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