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. Simple Signal Slot Question
Qt 6.11 is out! See what's new in the release blog

Simple Signal Slot Question

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 1.7k 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.
  • C Offline
    C Offline
    Crag_Hack
    wrote on last edited by Crag_Hack
    #1

    Hi my question is quite simple - I have a QDialog with a QDateTimeEdit and need to retrieve the datetime after the dialog closes. Is there a way to pass the datetimeedit's datetime to another QDateTime variable every time the value changes uses signals/slots - but without requiring a separate slot to change the value? Something like:

    QDateTime resetDateTime;
    QDateTimeEdit *partialDateTimeEdit = new QDateTimeEdit;
    partialDateTimeEdit->setDateTime(QDateTime::currentDateTime());
    connect(partialDateTimeEdit,SIGNAL(dateTimeChanged(QDateTime)),&resetDateTime,SLOT(changeTheValue(QDateTime)));
    

    Is there another better way?
    Thanks!

    jsulmJ 1 Reply Last reply
    0
    • C Crag_Hack

      Hi my question is quite simple - I have a QDialog with a QDateTimeEdit and need to retrieve the datetime after the dialog closes. Is there a way to pass the datetimeedit's datetime to another QDateTime variable every time the value changes uses signals/slots - but without requiring a separate slot to change the value? Something like:

      QDateTime resetDateTime;
      QDateTimeEdit *partialDateTimeEdit = new QDateTimeEdit;
      partialDateTimeEdit->setDateTime(QDateTime::currentDateTime());
      connect(partialDateTimeEdit,SIGNAL(dateTimeChanged(QDateTime)),&resetDateTime,SLOT(changeTheValue(QDateTime)));
      

      Is there another better way?
      Thanks!

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Crag_Hack No, QDateTime does not have such a slot. Why don't you want to implement your own slot? And why do you need this resetDateTime variable? If you want to retrieve datetime from the dialog then just add a getter:

      QDateTime MyDialog::dateTime()
      {
          return ui->dateTimeEdit->toLocalTime();
      }

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

      1 Reply Last reply
      2
      • C Offline
        C Offline
        Crag_Hack
        wrote on last edited by Crag_Hack
        #3

        Thanks jsulm. It turns out I had this code for the dialog:

        partialResetPrompt->setAttribute(Qt::WA_DeleteOnClose);
        

        So I couldn't grab the value after the dialog ended. Looks like removing the attribute allowed me to grab the value directly from the QDateTimeEdit widget. The dialog will eventually get deleted since its parent is my main window widget right? Also keep in mind this is a hard-coded model dialog no Qt Designer involved.

        jsulmJ 1 Reply Last reply
        0
        • C Crag_Hack

          Thanks jsulm. It turns out I had this code for the dialog:

          partialResetPrompt->setAttribute(Qt::WA_DeleteOnClose);
          

          So I couldn't grab the value after the dialog ended. Looks like removing the attribute allowed me to grab the value directly from the QDateTimeEdit widget. The dialog will eventually get deleted since its parent is my main window widget right? Also keep in mind this is a hard-coded model dialog no Qt Designer involved.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Crag_Hack Yes, it will be deleted with your main window if main window is the parent, or you delete it explicitly.

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

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

            Hi,

            Do you really need to delete it every time ? If so, using a local stack object would make more sense.

            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
            • C Offline
              C Offline
              Crag_Hack
              wrote on last edited by
              #6

              Brilliant! ha :)

              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