Results 1 to 10 of 10

Thread: date time to qtextedit??

  1. #1
    Join Date
    Oct 2009
    Location
    tathra nsw australia
    Posts
    14
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Unhappy date time to qtextedit??

    how do get date and/time from QDateTimeEdit, QTimeEdit QDateEdit ect
    to QTextEdit or QLineEdit QTableView ect.
    I am new at that this and my 70 year old brain hurts.

  2. #2
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: date time to qtextedit??

    you can get the QDate with "date()" and, after that, convert it into QString with "toString()" or use QDateTimeEdit::sectionAt() or QDateTimeEdit::sectionText(). After that, QTextEdit::setText()

  3. #3
    Join Date
    Oct 2009
    Location
    tathra nsw australia
    Posts
    14
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Thumbs down Re: date time to qtextedit??

    many thanks for your reply Jano...
    BUT i now don't know how to use them!!

    my code....
    QString str, str1, tr2, strdate;
    QDateTime datetime;

    value1 = spinBox1->value();
    value2 = spinBox2->value(); // these ok
    lcdnumber->display(value1 + value2);

    datetime = QDateTime(); // accepts this
    // strdate = QDateTime::toString; // but none of these
    // QDate::toString(datetime,"dd.MM.yyyy");
    // QTextEdit::setText(QDate::toString(Qt:ateFormat));
    // datetime = QDateTime::toString(currentDateTime());
    // textEdit->append("Current Date Time") + datetime;

    //QTextEdit::acceptRichText(false); also this fails

    textEdit->append("Path to file: " + lineEdit->text()); // these ok
    textEdit->append("Number 1 value: " + QString::number(value1));
    textEdit->append("Number 2 value: " + QString::number(value2));

    void QTextEdit::setText ( const QString & text ) [slot]
    perhaps it would help if i could understand what
    something this means ( const QString & text ) [slot]

    i need some examples
    regards and thanks
    Brian

  4. #4
    Join Date
    Oct 2009
    Location
    tathra nsw australia
    Posts
    14
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: date time to qtextedit??

    after much got these to work...

    QDateTime datetime = QDateTime::currentDateTime(); //works ok
    textEdit->append("date time is: " + datetime.toString()); // "

    this also works...
    // QString tr3 = datetime.toString(); // also works
    // textEdit->append("date is: " + tr3); // "

    both give me the required result

    NOW how do i get QDateTimeEdit settings to QTextEdit??????????

    I know what Qt functions to use but HOWWW??

    QtCreator is the ants pants

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,677
    Thanks
    13
    Thanked 1,596 Times in 1,524 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: date time to qtextedit??

    Quote Originally Posted by briang View Post
    NOW how do i get QDateTimeEdit settings to QTextEdit??????????
    I'm not sure what you mean by this. Which settings? How do they make sense in a text edit control?

    You already have the QDate expressed as a string, which you can stick into the text edit. You can tweak to format of the string with parameters to the toString method.

    If you want to embed a QDateTimeEdit control into the flow of text in a text edit then I don't think I can help.

  6. #6
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: date time to qtextedit??

    I don't really understand where is your problem.

    I think you want to have something like:


    Qt Code:
    1. //we already have a QTextEdit called "textEdit"
    2. QDateTime datetime = QDateTime::currentDateTime();
    3. //we want to have the hole current date
    4. QString strDate = datetime.toString();
    5. textEdit.setText(strDate);
    6. //we prefer to have only the day
    7. textEdit.clear();//clear :P
    8. QDate dDate = datetime.date();
    9. int iDay = dDate.day(); //get the day
    10. QString strDay = QString::number(iDay); //but we want it in QString, so we use the static function of QString "number"
    11. textEdit.setText(strDay);
    To copy to clipboard, switch view to plain text mode 


    Hope it helps... if you have any answer or you were asking another issue just ask again

  7. #7
    Join Date
    Oct 2009
    Location
    tathra nsw australia
    Posts
    14
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: date time to qtextedit??

    thanks for your reply

    what i want to do is put the DateTime shown in the
    QDateTimeEdit into the QTextEdit

    regards
    Briang

  8. #8
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: date time to qtextedit??

    Ok... is this?

    Qt Code:
    1. //we already have a QDateTimeEdit called "myDateTimeEdit"
    2. QDateTime datetime = QDateTime::currentDateTime();
    3. myDateTimeEdit.setDateTime(datetime);
    To copy to clipboard, switch view to plain text mode 

    the point I don't understand is a "QDateTimeEdit into a QTextEdit"

  9. The following user says thank you to jano_alex_es for this useful post:

    briang (16th October 2009)

  10. #9
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,677
    Thanks
    13
    Thanked 1,596 Times in 1,524 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: date time to qtextedit??

    This might be what you are after:
    Qt Code:
    1. // get the value from the edit
    2. QDateTime dateTime = dateTimeEdit.dateTime;
    3. // format with the same format as the date time edit
    4. QString timeDateString = dateTime.toString(dateTimeEdit.displayFormat());
    5. // do stuff with the time/date string
    6. ...
    To copy to clipboard, switch view to plain text mode 

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

    briang (16th October 2009)

  12. #10
    Join Date
    Oct 2009
    Location
    tathra nsw australia
    Posts
    14
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Talking Re: date time to qtextedit??

    G'day Jano and Chris

    YES that is exactly what i was after

    QDateTime datetime1 = QDateTime::currentDateTime(); //sets QDateTimeEdit to today.
    dateTimeEdit->setDateTime(datetime1);

    QDateTime datetime2 = dateTimeEdit->dateTime(); //prints QDateTimeEdit to textEdit
    QString timeDateString = datetime2.toString(dateTimeEdit->displayFormat());
    textEdit->append(timeDateString); |
    Chris you show a full stop here but when i press fullstop i get this automatically.
    i did not know this to till now.

    At the moment i am just trying out how the various widgets interconnect.
    am now going to attack QTable ect.

    using Qt Creator 1.2.1 Qt4.5.2 (64bit) on kde4.3.1

    THANK YOU THANK YOU both

    Qt Creator is the ants pants.

    regards to you both
    Brian.

Similar Threads

  1. time and date issues
    By boog07005 in forum Newbie
    Replies: 5
    Last Post: 20th August 2012, 16:15
  2. QTextEdit loading takes long time
    By sreedhar in forum Qt Programming
    Replies: 12
    Last Post: 21st March 2011, 11:29
  3. How to change the date and time of a system
    By augusbas in forum Qt Programming
    Replies: 1
    Last Post: 23rd June 2009, 06:55
  4. automatic time and date updating
    By sudheer in forum Qt Tools
    Replies: 1
    Last Post: 17th January 2008, 11:00
  5. to set date and time in the file info of two days back
    By thomasjoy in forum Qt Programming
    Replies: 1
    Last Post: 11th October 2007, 17:54

Tags for this Thread

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.