PDA

View Full Version : date time to qtextedit??



briang
9th October 2009, 07:53
how do get date and/time from QDateTimeEdit, QTimeEdit QDateEdit ect
to QTextEdit or QLineEdit QTableView ect.:confused:
I am new at that this and my 70 year old brain hurts.

jano_alex_es
9th October 2009, 08:24
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()

briang
10th October 2009, 04:46
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::DateFormat) );
// 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:confused:
regards and thanks
Brian

briang
15th October 2009, 04:57
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:cool:

ChrisW67
15th October 2009, 05:59
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.

jano_alex_es
15th October 2009, 08:30
I don't really understand where is your problem.

I think you want to have something like:




//we already have a QTextEdit called "textEdit"
QDateTime datetime = QDateTime::currentDateTime();
//we want to have the hole current date
QString strDate = datetime.toString();
textEdit.setText(strDate);
//we prefer to have only the day
textEdit.clear();//clear :P
QDate dDate = datetime.date();
int iDay = dDate.day(); //get the day
QString strDay = QString::number(iDay); //but we want it in QString, so we use the static function of QString "number"
textEdit.setText(strDay);



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

briang
15th October 2009, 11:34
thanks for your reply

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

regards
Briang

jano_alex_es
15th October 2009, 11:41
Ok... is this?



//we already have a QDateTimeEdit called "myDateTimeEdit"
QDateTime datetime = QDateTime::currentDateTime();
myDateTimeEdit.setDateTime(datetime);


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

ChrisW67
15th October 2009, 22:08
This might be what you are after:


// get the value from the edit
QDateTime dateTime = dateTimeEdit.dateTime;
// format with the same format as the date time edit
QString timeDateString = dateTime.toString(dateTimeEdit.displayFormat());
// do stuff with the time/date string
...

briang
16th October 2009, 05:29
G'day Jano and Chris

YES that is exactly what i was after:):D

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.