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. Problem with QCalendarWidget_clicked
Forum Updated to NodeBB v4.3 + New Features

Problem with QCalendarWidget_clicked

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 273 Views
  • 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
    Chaki
    wrote on last edited by
    #1

    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");
            //}
        }
    }
    
    JonBJ 1 Reply Last reply
    0
    • C Chaki

      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");
              //}
          }
      }
      
      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by JonB
      #2

      @Chaki
      So it doesn't match whatever on the final iteration. Move the setText("no Match") out of the loop, put it before the for.

      StringList.at(i+1) looks dodgy. It will go over the bounds at the end. Can't see why it's not StringList.at(i).

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

        @JonB Thank you very much Sir, your answer worked perfectly!

        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