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


  • Moderators

    text() is a getter. you want to use the setter: setText(). Also label1 is a pointer so use -> instead of ..
    currentDateTime() is static, so you don't need to create instance of QDateTime 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());
    }
    
    

  • Qt Champions 2016

    Hi
    you can remove
    QDateTime time;


  • Moderators

    This post is deleted!

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.