QDateTimeEdit DateTimeChanged
-
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.
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. } } }
-
@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? -
@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.
-
@Phamy1289 said in QDateTimeEdit DateTimeChanged:
pMyDateTime.dateTimeChanged(mpStartDateTime->dateTime());
Why do you call a signal here?!
Why not simplyQDateTimeEdit *pMyDateTime = new QDateTimeEdit(mpStartDateTime->dateTime());
?
-
Hi,
That's what the signal is for.
-
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); }
-
@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? -
@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.
-
@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
.