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. QDateTimeEdit DateTimeChanged
Qt 6.11 is out! See what's new in the release blog

QDateTimeEdit DateTimeChanged

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 4 Posters 1.7k Views 1 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.
  • P Phamy1289

    I have a calendar popup for my start date. I want to be able to select the date and save the changed date to a variable to filter out a list based on the date in my QTableWidget. I don't know what I'm doing wrong as the variable that suppose to save the date keeps showing 1/1/00 12:00am instead of the date and time I'm selecting.

    5a7fcac7-f142-4e10-8fae-936b908cfeb2-image.png

    QGroupBox *ScheduleAdvice::mpDateGroup()
    {
       QGroupBox *pGroupBox = new QGroupBox;
       pGroupBox->setStyleSheet("border:0");
       QHBoxLayout *pDateLayout = new QHBoxLayout;
    
       mpStartDateTime = new QDateTimeEdit;
       mpStartDateTime->setCalendarPopup(true);
       mpStartDateTime->setDisplayFormat("yyyy/MM/dd hh:mm:ss");
       mpStartDateTime->setDateTime(QDateTime::currentDateTime());
       mpStartDateTime->setStyleSheet("color: black");
    
       pDateLayout->addWidget(mpStartDateTime);
    
       pGroupBox->setLayout(pDateLayout);
    }
    
    void ScheduleAdvice::handle(QNetworkReply reply)
    {
       //Reading in QJSON 
    
       for(auto it =root.begin(); it != root.end(); ++it)
       {
          QDateTimeEdit *pMyDateTime = new QDateTimeEdit;
          pMyDateTime.dateTimeChanged(mpStartDateTime->dateTime());
          
          if(it.key().toString() >= pMyDateTime->text())
          {
             qDebug() << pMyDateTime->text();
             //start filtering list in QTableWidget.
          }
       }
    }
    
    jsulmJ Online
    jsulmJ Online
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #2

    @Phamy1289 said in QDateTimeEdit DateTimeChanged:

    as the variable that suppose to save the date

    Which variable is that and where do you set it?
    Is it myDateTime? If so: where do you set it?
    You set pMyDateTime, but then you check myDateTime, why?

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    P 1 Reply Last reply
    0
    • jsulmJ jsulm

      @Phamy1289 said in QDateTimeEdit DateTimeChanged:

      as the variable that suppose to save the date

      Which variable is that and where do you set it?
      Is it myDateTime? If so: where do you set it?
      You set pMyDateTime, but then you check myDateTime, why?

      P Offline
      P Offline
      Phamy1289
      wrote on last edited by Phamy1289
      #3

      @jsulm Sorry that's a typo. let me fix it. I was hoping to store the mpStartDateTime into the variable pMyDateTime whenever mpStartDate gets a change in the date and time. For example, the date changes from the current date to date 2 years ago. From 11/5/2021 to 02/15/2019. I want pMyDateTime to store 02/15/2019. If mpStartDateTime were to change dates and/or time again, then pMyDateTime would store the new date and/or time.

      1 Reply Last reply
      0
      • P Phamy1289

        I have a calendar popup for my start date. I want to be able to select the date and save the changed date to a variable to filter out a list based on the date in my QTableWidget. I don't know what I'm doing wrong as the variable that suppose to save the date keeps showing 1/1/00 12:00am instead of the date and time I'm selecting.

        5a7fcac7-f142-4e10-8fae-936b908cfeb2-image.png

        QGroupBox *ScheduleAdvice::mpDateGroup()
        {
           QGroupBox *pGroupBox = new QGroupBox;
           pGroupBox->setStyleSheet("border:0");
           QHBoxLayout *pDateLayout = new QHBoxLayout;
        
           mpStartDateTime = new QDateTimeEdit;
           mpStartDateTime->setCalendarPopup(true);
           mpStartDateTime->setDisplayFormat("yyyy/MM/dd hh:mm:ss");
           mpStartDateTime->setDateTime(QDateTime::currentDateTime());
           mpStartDateTime->setStyleSheet("color: black");
        
           pDateLayout->addWidget(mpStartDateTime);
        
           pGroupBox->setLayout(pDateLayout);
        }
        
        void ScheduleAdvice::handle(QNetworkReply reply)
        {
           //Reading in QJSON 
        
           for(auto it =root.begin(); it != root.end(); ++it)
           {
              QDateTimeEdit *pMyDateTime = new QDateTimeEdit;
              pMyDateTime.dateTimeChanged(mpStartDateTime->dateTime());
              
              if(it.key().toString() >= pMyDateTime->text())
              {
                 qDebug() << pMyDateTime->text();
                 //start filtering list in QTableWidget.
              }
           }
        }
        
        jsulmJ Online
        jsulmJ Online
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #4

        @Phamy1289 said in QDateTimeEdit DateTimeChanged:

        pMyDateTime.dateTimeChanged(mpStartDateTime->dateTime());

        Why do you call a signal here?!
        Why not simply

        QDateTimeEdit *pMyDateTime = new QDateTimeEdit(mpStartDateTime->dateTime());
        

        ?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • P Offline
          P Offline
          Phamy1289
          wrote on last edited by
          #5

          So, now that i'm getting the right dateTime from mpStartDateTime, how do I keep track of the new dateTime in mpStartDateTime if the user selects a different date from the calendar?

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #6

            Hi,

            That's what the signal is for.

            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
            0
            • P Offline
              P Offline
              Phamy1289
              wrote on last edited by
              #7

              The date isn't changing when I change the date. Am I using the signal/slot incorrectly? mpStartDateTime is and QDateTimeEdit and is set to the current date and time when the application launches, I don't know if that matters or not.

              connect(mpStartDateTime, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(updateDateTime(const QDateTime)));
              
                          for(auto it = root.begin(); it != root.end(); ++it)
                          {
                              if(it.key() == "startDate")
                              {
                                  if(it.value().toString() >= mpStartDateTime->text())
                                  {
                                      std::cout << mpStartDateTime->text().toStdString() << " ";
                                  }
                                  else
                                  {
                                      std::cout << mpStartDateTime->text().toStdString() << " ";
                                  }
                              }
              
              void ScheduleAdvice::updateDateTime(const QDateTime dateTime)
              {
                  mpStartDateTime->setDateTime(dateTime);
              }
              
              JonBJ jsulmJ 2 Replies Last reply
              0
              • P Phamy1289

                The date isn't changing when I change the date. Am I using the signal/slot incorrectly? mpStartDateTime is and QDateTimeEdit and is set to the current date and time when the application launches, I don't know if that matters or not.

                connect(mpStartDateTime, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(updateDateTime(const QDateTime)));
                
                            for(auto it = root.begin(); it != root.end(); ++it)
                            {
                                if(it.key() == "startDate")
                                {
                                    if(it.value().toString() >= mpStartDateTime->text())
                                    {
                                        std::cout << mpStartDateTime->text().toStdString() << " ";
                                    }
                                    else
                                    {
                                        std::cout << mpStartDateTime->text().toStdString() << " ";
                                    }
                                }
                
                void ScheduleAdvice::updateDateTime(const QDateTime dateTime)
                {
                    mpStartDateTime->setDateTime(dateTime);
                }
                
                JonBJ Online
                JonBJ Online
                JonB
                wrote on last edited by
                #8

                @Phamy1289
                Start by putting qDebug() << dateTime; into updateDateTime. Is it called at all, is the value correct?

                P 1 Reply Last reply
                0
                • P Phamy1289

                  The date isn't changing when I change the date. Am I using the signal/slot incorrectly? mpStartDateTime is and QDateTimeEdit and is set to the current date and time when the application launches, I don't know if that matters or not.

                  connect(mpStartDateTime, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(updateDateTime(const QDateTime)));
                  
                              for(auto it = root.begin(); it != root.end(); ++it)
                              {
                                  if(it.key() == "startDate")
                                  {
                                      if(it.value().toString() >= mpStartDateTime->text())
                                      {
                                          std::cout << mpStartDateTime->text().toStdString() << " ";
                                      }
                                      else
                                      {
                                          std::cout << mpStartDateTime->text().toStdString() << " ";
                                      }
                                  }
                  
                  void ScheduleAdvice::updateDateTime(const QDateTime dateTime)
                  {
                      mpStartDateTime->setDateTime(dateTime);
                  }
                  
                  jsulmJ Online
                  jsulmJ Online
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by jsulm
                  #9

                  @Phamy1289 said in QDateTimeEdit DateTimeChanged:

                  connect(mpStartDateTime, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(updateDateTime(const QDateTime)));

                  I don't understand what you're trying to do.
                  You connect a signal from mpStartDateTime and in the slot connected to that signal you change mpStartDateTime - what's the point?

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  1
                  • JonBJ JonB

                    @Phamy1289
                    Start by putting qDebug() << dateTime; into updateDateTime. Is it called at all, is the value correct?

                    P Offline
                    P Offline
                    Phamy1289
                    wrote on last edited by Phamy1289
                    #10

                    @JonB It does comeback with the correct value.

                    @jsulm I have a calendar popup and table full of data from a QJSON where start date is one of them attributes. I want to be able to filter that data with the date selected from the popup which the user can choose the date. I would like this to update live as the user changes the start date.

                    3a6a4206-4eb4-452c-80c5-71aef6ae8dad-image.png

                    JonBJ 1 Reply Last reply
                    0
                    • P Phamy1289

                      @JonB It does comeback with the correct value.

                      @jsulm I have a calendar popup and table full of data from a QJSON where start date is one of them attributes. I want to be able to filter that data with the date selected from the popup which the user can choose the date. I would like this to update live as the user changes the start date.

                      3a6a4206-4eb4-452c-80c5-71aef6ae8dad-image.png

                      JonBJ Online
                      JonBJ Online
                      JonB
                      wrote on last edited by JonB
                      #11

                      @Phamy1289 said in QDateTimeEdit DateTimeChanged:

                      @JonB It does comeback with the correct value.

                      In that case you can be sure that mpStartDateTime->setDateTime(dateTime); sets that value into *mpStartDateTime.

                      P 1 Reply Last reply
                      0
                      • JonBJ JonB

                        @Phamy1289 said in QDateTimeEdit DateTimeChanged:

                        @JonB It does comeback with the correct value.

                        In that case you can be sure that mpStartDateTime->setDateTime(dateTime); sets that value into *mpStartDateTime.

                        P Offline
                        P Offline
                        Phamy1289
                        wrote on last edited by
                        #12

                        @JonB You're right. I did a test and it does update mpStartDateTime. Thank you!

                        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