Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Error for get date
Qt 6.11 is out! See what's new in the release blog

Error for get date

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 1.1k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Armin
    wrote on last edited by
    #1

    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

    A 1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #2

      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();

      1 Reply Last reply
      5
      • A Offline
        A Offline
        Armin
        wrote on last edited by
        #3

        Thanks
        i replace this code :

        void MainWindow::on_pushButton_clicked()
        {
            QDateTime time;
            auto tt = time.currentDateTime();
            ui->label1->setText(tt.toString());
        }
        
        
        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi
          you can remove
          QDateTime time;

          1 Reply Last reply
          1
          • A Armin

            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

            A Offline
            A Offline
            ambershark
            wrote on last edited by
            #5
            This post is deleted!
            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved