Results 1 to 19 of 19

Thread: Change date not working

  1. #1
    Join Date
    Apr 2012
    Posts
    39
    Thanks
    7

    Exclamation Change date not working

    Hi I'm trying to reschedule a QDate, but do not know why that is not working.

    I have the following code:

    Qt Code:
    1. qDebug() << ano2;
    2. qDebug() << mes2;
    3. qDebug() << dia2;
    4.  
    5. bool b = ui->data_inicio->date().setDate(ano2, mes2, dia2);
    6. qDebug () << b;
    To copy to clipboard, switch view to plain text mode 



    In qDebug appears fine. Until b returns true.

    Why does not the date and amended?




    regards,
    Daniel Sousa

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Change date not working

    Not enough info. read sig.

    Most likely date() returns a temporary and not the actual date object used in data_inicio. This is where reading the docs comes in handy.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Change date not working

    date() returns a copy of the object. Calling setDate() on that will change the copy and not the original date object.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Apr 2012
    Posts
    39
    Thanks
    7

    Default Re: Change date not working

    Quote Originally Posted by amleto View Post
    Not enough info. read sig.

    Most likely date() returns a temporary and not the actual date object used in data_inicio. This is where reading the docs comes in handy.
    But I've been reading and I do not understand the problem.

    I do not know and explain how I change the date of a QDate through the code?

  5. #5
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Change date not working

    you've been reading? So you saw this http://qt-project.org/doc/qt-4.8/qdatetime.html#setDate ?
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  6. #6
    Join Date
    Apr 2012
    Posts
    39
    Thanks
    7

    Default Re: Change date not working

    Quote Originally Posted by amleto View Post
    you've been reading? So you saw this http://qt-project.org/doc/qt-4.8/qdatetime.html#setDate ?
    And that's what I did. The following code should work right?

    bool b = ui->data_inicio->date().setDate(2012, 10, 5);

  7. #7
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Change date not working

    ui->data_inicio->date()
    And what does this method return? Does it return QDate? Or QDate & ? If it returns QDate, then this is a temporary, a copy of the QDate stored in data_incio. Changing the copy has no effect at all on on the original QDate stored in data_incio.

    Of course the setDate() function call will return true, because even if the QDate is a temporary, setting it to a new date will work just fine. It just has no effect, because at the end of that line of code, the copy is destroyed and whatever changes you made go with it.
    Last edited by d_stranz; 8th May 2012 at 17:43.

  8. #8
    Join Date
    Apr 2012
    Posts
    39
    Thanks
    7

    Default Re: Change date not working

    Quote Originally Posted by d_stranz View Post
    And what does this method return? Does it return QDate? Or QDate & ? If it returns QDate, then this is a temporary, a copy of the QDate stored in data_incio. Changing the copy has no effect at all on on the original QDate stored in data_incio.

    Of course the setDate() function call will return true, because even if the QDate is a temporary, setting it to a new date will work just fine. It just has no effect, because at the end of that line of code, the copy is destroyed and whatever changes you made go with it.
    But then how can I do this?

  9. #9
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Change date not working

    Quote Originally Posted by sousadaniel7 View Post
    And that's what I did. The following code should work right?

    bool b = ui->data_inicio->date().setDate(2012, 10, 5);
    no, that's not what you did, and no, it shouldn't work.

    Look carefully!
    http://qt-project.org/doc/qt-4.8/qdatetime.html#setDate
    http://qt-project.org/doc/qt-4.8/qdate.html#setDate

    and try again...
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Change date not working

    Quote Originally Posted by sousadaniel7 View Post
    But then how can I do this?
    Maybe you should call setDate() on the ui->data_inicio object?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Change date not working

    Maybe you should call setDate() on the ui->data_inicio object?
    Or maybe, since Daniel won't tell us what "data_inico" is, we can just keep guessing at answers until one of us guesses correctly.

  12. #12
    Join Date
    Apr 2012
    Posts
    39
    Thanks
    7

    Default Re: Change date not working

    Quote Originally Posted by d_stranz View Post
    Or maybe, since Daniel won't tell us what "data_inico" is, we can just keep guessing at answers until one of us guesses correctly.
    ui->data_inicio is a QDateEdit

    I've tried many ways and I can not change its value ...

  13. #13
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Change date not working

    try reading the thread

    try reading the docs http://qt-project.org/doc/qt-4.8/qda...blic-functions
    Last edited by amleto; 17th May 2012 at 23:37.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  14. #14
    Join Date
    Apr 2012
    Posts
    39
    Thanks
    7

    Default Re: Change date not working

    I managed to solve the problem.

    Now I can not and the pm or am a QTimeEdit. I've had to do the builders and they do not allow for it ... How do I solve this?

  15. #15
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Change date not working

    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  16. #16
    Join Date
    Apr 2012
    Posts
    39
    Thanks
    7

    Default Re: Change date not working

    I have the following code.

    Qt Code:
    1. QStringList list_hora_inicio = fg.separarHora(query.value(8).toString());
    2. QString horaInicio = list_hora_inicio[0];
    3. QString minutosInicio = list_hora_inicio[1];
    4. QString amanha_tarde = list_hora_inicio[2];
    5. ui->hora_incio->setTime(QTime(horaInicio.toInt(&ok, 10), minutosInicio.toInt(&ok, 10)));
    To copy to clipboard, switch view to plain text mode 

    Where do I put the AM or PM?

  17. #17
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Change date not working

    is there a brick wall I can borrow? ...

    spoon feeding ...
    qt-project.org/doc/qt-4.8/qdatetime.html#fromString
    Last edited by amleto; 18th May 2012 at 00:32.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  18. #18
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Change date not working

    Quote Originally Posted by sousadaniel7 View Post
    Where do I put the AM or PM?
    You don't. You read the documentation... it is obvious. I'll even highlight the bit that answers your question
    QTime::QTime ( int h, int m, int s = 0, int ms = 0 )

    Constructs a time with hour h, minute m, seconds s and milliseconds ms.
    h must be in the range 0 to 23, m and s must be in the range 0 to 59, and ms must be in the range 0 to 999.
    What is 3 PM on a 24-hour clock?
    "We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
    If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.

  19. The following user says thank you to ChrisW67 for this useful post:

    sousadaniel7 (18th May 2012)

  20. #19
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Change date not working

    @amleto: is there a brick wall I can borrow? ...
    Sorry, I'm using that wall right now. If you can answer the question in my post, I will let you have the wall until I need it again.

Similar Threads

  1. Change colors of date of calendarwidget
    By moh.gup@gmail.com in forum Qt Programming
    Replies: 0
    Last Post: 6th April 2010, 19:36
  2. How to change computer's Clock and Date
    By anafor2004 in forum Newbie
    Replies: 1
    Last Post: 24th October 2009, 15:18
  3. How to change the date and time of a system
    By augusbas in forum Qt Programming
    Replies: 1
    Last Post: 23rd June 2009, 05:55
  4. Minimum date change
    By fnmblot in forum Qt Programming
    Replies: 2
    Last Post: 16th August 2006, 21:22
  5. Working with Date type in database applications
    By kolach in forum Qt Programming
    Replies: 13
    Last Post: 25th January 2006, 14:20

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.