Important: Please read the Qt Code of Conduct -

Simple Signal Slot Question

  • 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;

    Is there another better way?

  • Qt Champions 2019

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

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


    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.

  • Qt Champions 2019

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

  • Lifetime Qt Champion


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

  • Brilliant! ha :)

Log in to reply