Problem with passing QDateTimeEdit to QString
-
Hi everybody ,im working on a project in wichi i have a QTimeEdit object . So i added a signal slot
The idea is to send via serial communication the data but first i want to check if the conversion QDateTimeEdit to QString is correctly being made .. but no :S .
I put a text label (QPlaintTextEdit ) so to print the QDateTimeEdit there and verify that the conversion is right.void MainWindow::on_dateTimeEdit_editingFinished()
{
QDate aux_date;
QString str_date;
QString str_time;
QTime aux_time;
aux_date = ui->dateTimeEdit->date();
aux_date.toString(str_date);
aux_time = ui->dateTimeEdit->time();
aux_time.toString(str_time);
str_date.append(str_time); //ahora tengo todo los datos en el string str_date
ui->texto_prueba->setPlainText(str_date); // texto_prueba is a QPlaintTextEdit object}
-
Hi, you code is wrong.
@
str_date = aux_date.toString();
@ -
thank you, i was using the wrong function
now i have this:
void MainWindow::on_dateTimeEdit_editingFinished()
{
QDate aux_date;QTime aux_time; QString str_date; QString str_time; QString format = "dd.MM.yyyy"; int horas,minuts,segundos,tiempo; aux_date = ui->dateTimeEdit->date(); str_date = aux_date.toString(format);
aux_time = ui->dateTimeEdit->time();
str_time = aux_time.toString("hh:mm:ss AP");
the conversion of the QDateTimeEdit to QString works perfect.
I have the str_date in the format of "dd.MM.yyyy" , now i need to have:
int day = dd;
int month = MM;
int year = yyyy;
the same with the str_time , the format is hh:mm:ss AP :
int sec = ss;
int min = mm;
int hour = hh;
how can i make that ??
anyidea on how can i send 'AM' or 'PM' ?thanks
-
Hi,
Use QDate and QTime returned form QDateTime::date() and QDateTime::time(). For the AM/PM you can retrieve them using toString.
Also please, use coding tags around your code, otherwise it makes it very hard to read.