Problem with QtDateTime



  • 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!!


  • Moderators

    [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 ;)



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.