Solved Problem with QCalendarWidget_clicked
-
Hello, I am currently trying to work with the on_CalendarWidget_clicked Signal with the following code. My problem is, that the if-Statement only works, as long as I don't use the else.
Whenever I try to use the else-Statement, the if-Statement is never correct and it always prints out "no Match".the StringList is constructed: date(dd.MM.yyyy), someHoliday, date(dd.MM.yyyy), someHoliday, ...
void MainWindow::on_myCalendarWidget_clicked(const QDate &date) { QString clickedDate = date.toString("dd.MM.yyyy"); for(int i = 0; i<StringList.size(); i++){ QString actualDate = StringList.at(i); if((actualDate.compare(clickedDate))==0){ ui->textEdit->setText(StringList.at(i+1)); }//else{ //ui->textEdit->setText("no Match"); //} } }
-
@Chaki
So it doesn't match whatever on the final iteration. Move thesetText("no Match")
out of the loop, put it before thefor
.StringList.at(i+1)
looks dodgy. It will go over the bounds at the end. Can't see why it's notStringList.at(i)
. -
@Chaki
So it doesn't match whatever on the final iteration. Move thesetText("no Match")
out of the loop, put it before thefor
.StringList.at(i+1)
looks dodgy. It will go over the bounds at the end. Can't see why it's notStringList.at(i)
. -
@JonB Thank you very much Sir, your answer worked perfectly!