Results 1 to 8 of 8

Thread: other time...can't get date

  1. #1
    Join Date
    Aug 2009
    Posts
    38
    Thanks
    3

    Default other time...can't get date

    Hi.

    I do:

    QString pepelu = lineaHora.left(6)+lineaHora.right(5);
    QDateTime dias = QDateTime::fromString(pepelu,"yyMMddhhmm");

    it gives me: 1003030900

    I do:

    hora->setText("Timess: " + dias.toString("yyMMddhhmm"));

    But doesn't show me nothing in my label

    Any help?
    Many thanks and sorry for my english!

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: other time...can't get date

    Then something with your label is not right.
    Qt Code:
    1. QDateTime dias;
    2. dias.setTime_t(1003030900);
    3. QLabel l;
    4. l.setText(dias.toString("yyMMddhhmm"));
    5. l.show();
    To copy to clipboard, switch view to plain text mode 
    works perfect. See if dias is valid where you want to use it. It seems to me your code confuses allocation on the heap and stack. Show us a little more code.

  3. #3
    Join Date
    Aug 2009
    Posts
    38
    Thanks
    3

    Default Re: other time...can't get date

    Many thanks!

    More code:
    Qt Code:
    1. file2.open(QIODevice::ReadOnly);
    2. while (!file2.atEnd()) {
    3.  
    4. QByteArray lineaHora = file2.readLine();
    5.  
    6. QString comHora = lineaHora.left(6);
    7. QString comMinuto = lineaHora.right(5);
    8. // asi me coge la hora
    9. //BIEN QTime dias = QTime::fromString(comHora,"hms");
    10.  
    11. //QDateTime dias = QDateTime::fromString(comHora,"dd/MM/yy");
    12. //QDate dia = QDate::fromString(comHora,"yyMMdd");
    13. //QString pepelu = comHora+comMinuto;
    14.  
    15. QString pepelu = lineaHora.left(6)+lineaHora.right(5);
    16. QDateTime dias = QDateTime::fromString(pepelu,"yyMMddhhmm");
    17.  
    18. //BIEN hora->setText("Timess: " + dia.toString("yyMMdd"));
    19. // hora->setText("Timess: " + dias.toString("yyMMdd"));
    20.  
    21. hora->setText("Timess: " + dias.toString("yyMMddhhmm"));
    22.  
    23.  
    24. QMessageBox::information(this, "resultado",pepelu);
    25. QMessageBox::information(this, "resultado",lineaHora.left(6));
    26. QMessageBox::information(this, "resultado",lineaHora.right(5));
    27. //QMessageBox::information(this, "resultado",dia.toString());
    28.  
    29. //item->setText(line2);
    30. //tabla->setItem(c,1,item);
    31. //c++;
    32. }
    33. }
    To copy to clipboard, switch view to plain text mode 

    Thanks a lot,

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: other time...can't get date

    ok, first
    Qt Code:
    1. QString pepelu = lineaHora.left(6)+lineaHora.right(5);
    2. QDateTime dias = QDateTime::fromString(pepelu,"yyMMddhhmm");
    To copy to clipboard, switch view to plain text mode 
    6+5 = 11. yyMMddhhmm == 10! I think.

    Then in the while loop you set the result every time on the same label. And I guess your last line which is precessed in an empty line. So the label will show nothing.

  5. #5
    Join Date
    Aug 2009
    Posts
    38
    Thanks
    3

    Default Re: other time...can't get date

    Well, is something strange
    The file have:

    100303-0900
    100303-1015
    100303-1400
    100303-1430

    If I do:

    QMessageBox::information(this, "resultado",lineaHora.right(6))

    Gives me -1400

    QMessageBox::information(this, "resultado",lineaHora.right(5))

    Gives me 1400 when I think that if would give me: "-1400"

    Many thanks and sorry for my english!

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: other time...can't get date

    Quote Originally Posted by mmm286 View Post
    If I do:

    QMessageBox::information(this, "resultado",lineaHora.right(6))

    Gives me -1400

    QMessageBox::information(this, "resultado",lineaHora.right(5))

    Gives me 1400 when I think that if would give me: "-1400"
    Read the docs about readLine():
    The newline character ('\n') is included in the buffer.
    Therefore you have to QByteArray::chop() first.

  7. #7
    Join Date
    Aug 2009
    Posts
    38
    Thanks
    3

    Default Re: other time...can't get date

    Many thanks!!!

  8. #8
    Join Date
    Aug 2009
    Posts
    38
    Thanks
    3

    Default Re: other time...can't get date

    Many thanks!!!

Similar Threads

  1. time and date issues
    By boog07005 in forum Newbie
    Replies: 5
    Last Post: 20th August 2012, 15:15
  2. Date and Time Difference
    By MIH1406 in forum Newbie
    Replies: 4
    Last Post: 20th August 2012, 15:03
  3. Date and Time format.
    By kaushal_gaurav in forum Qt Programming
    Replies: 3
    Last Post: 12th August 2008, 11:36
  4. Date Time
    By starcontrol in forum Qt Programming
    Replies: 3
    Last Post: 4th April 2008, 11:02
  5. date-time problem
    By aegis in forum Qt Programming
    Replies: 5
    Last Post: 11th February 2007, 18:45

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.