Solved 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; partialDateTimeEdit->setDateTime(QDateTime::currentDateTime()); connect(partialDateTimeEdit,SIGNAL(dateTimeChanged(QDateTime)),&resetDateTime,SLOT(changeTheValue(QDateTime)));
Is there another better way?
Thanks! -
@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:
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.
-
@Crag_Hack Yes, it will be deleted with your main window if main window is the parent, or you delete it explicitly.
-
Hi,
Do you really need to delete it every time ? If so, using a local stack object would make more sense.
-
Brilliant! ha :)