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. I want to get date from Date edit
Forum Updated to NodeBB v4.3 + New Features

I want to get date from Date edit

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 3 Posters 13.4k Views 2 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 Armin

    Thanks for share
    Two question:

    1-Why you use ui ?
    2- i write this code and get error :

    void MainWindow::on_pushButton_clicked()
    {
        QDate = ui->dateEdit->date();
        String dateString = date.toString();
    
    
    }
    
    SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #4

    Hi and welcome to devnet,

    1. Like @mrjj wrote, that's valid if you used a Designer based form.
    2. String is not a Qt class, the name is QString.

    By the way, what exact error are you getting ?

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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

      Thanks
      i have this error :

      error: expected unqualified-id before '=' token
      QDate = dateEdit->date();
      ^
      error: 'date' was not declared in this scope
      QString dateString = date.toString();
      ^

      and this is my code:

      void MainWindow::on_pushButton_clicked()
      {
          QDate = dateEdit->date();
          QString dateString = date.toString();
      
      
      }
      
      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #6

        Your are missing the variable name between QDate and =

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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

          and i get error again:

          error: 'dateEdit' was not declared in this scope
          QDate test = dateEdit->date();
          ^

          error: 'date' was not declared in this scope
          QString dateString = date.toString();
          ^

          warning: unused variable 'test' [-Wunused-variable]
          QDate test = dateEdit->date();
          ^

          1 Reply Last reply
          0
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by mrjj
            #8

            Sorry was not ok sample :)

            
            QDate myDate= ui->dateEdit->date(); // this is only vlaid if u visually design the window and placed dateEdit
            QString dateString = myDate.toString();
            
            A 1 Reply Last reply
            1
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #9

              You named your QDate variable test and then you use date in the following line hence the error and the warning.

              As for the dateEdit not declared, you don't have any member variable declared nor initalized with that name.

              Looks like you're new to C++, please take the time to learn the basics.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              A 1 Reply Last reply
              1
              • mrjjM mrjj

                Sorry was not ok sample :)

                
                QDate myDate= ui->dateEdit->date(); // this is only vlaid if u visually design the window and placed dateEdit
                QString dateString = myDate.toString();
                
                A Offline
                A Offline
                Armin
                wrote on last edited by
                #10

                @mrjj

                Thanks for share
                I solve my problem

                1 Reply Last reply
                1
                • SGaistS SGaist

                  You named your QDate variable test and then you use date in the following line hence the error and the warning.

                  As for the dateEdit not declared, you don't have any member variable declared nor initalized with that name.

                  Looks like you're new to C++, please take the time to learn the basics.

                  A Offline
                  A Offline
                  Armin
                  wrote on last edited by
                  #11

                  @SGaist
                  Thank you
                  Solve

                  mrjjM 1 Reply Last reply
                  0
                  • A Armin

                    @SGaist
                    Thank you
                    Solve

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #12

                    @Armin
                    Super Please select Topic Tools button and mark as Question and then select Solved.

                    A 1 Reply Last reply
                    0
                    • mrjjM mrjj

                      @Armin
                      Super Please select Topic Tools button and mark as Question and then select Solved.

                      A Offline
                      A Offline
                      Armin
                      wrote on last edited by mrjj
                      #13

                      @mrjj
                      Thanks
                      I did it . correct?
                      mrjj: yes :)

                      1 Reply Last reply
                      1

                      • Login

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