Unsolved Error for get date
-
Hi
I write this code but get error :void MainWindow::on_pushButton_clicked() { QDateTime time; auto tt = time.currentDateTime(); ui->label1.text(tt.toString()); }
Error:
request for member 'text' in '((MainWindow*)this)->MainWindow::ui->Ui::MainWindow::<anonymous>.Ui_MainWindow::label1', which is of pointer type 'QLabel*' (maybe you meant to use '->' ?)
ui->label1.text(tt.toString());
^Why i get error?
thanks -
text()
is a getter. you want to use the setter:setText()
. Alsolabel1
is a pointer so use->
instead of.
.
currentDateTime()
is static, so you don't need to create instance ofQDateTime
to use it:auto tt = QDateTime::currentDateTime();
-
Thanks
i replace this code :void MainWindow::on_pushButton_clicked() { QDateTime time; auto tt = time.currentDateTime(); ui->label1->setText(tt.toString()); }
-
Hi
you can remove
QDateTime time; -
This post is deleted!