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. How to set QDate more than once ?
Forum Updated to NodeBB v4.3 + New Features

How to set QDate more than once ?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 556 Views 2 Watching
  • 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.
  • sonichyS Offline
    sonichyS Offline
    sonichy
    wrote on last edited by
    #1

    When I set QDate1 = QDate2 more then once, it will cause program crash !

    https://github.com/sonichy

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      That sounds odd.
      Unless QDate1 and QDate2 are pointers, then it seems almost impossible.

      Can you show the actual code ?

      sonichyS 1 Reply Last reply
      1
      • mrjjM mrjj

        Hi
        That sounds odd.
        Unless QDate1 and QDate2 are pointers, then it seems almost impossible.

        Can you show the actual code ?

        sonichyS Offline
        sonichyS Offline
        sonichy
        wrote on last edited by
        #3

        @mrjj When I have not click the cell of QTableWidget, and press next mouth, the currentCellChanged(cr=-1, cc=-1) cause error.

        connect(ui->pushButton_nextmonth,SIGNAL(released()),this,SLOT(nextMonth()));
        connect(ui->tableWidget,SIGNAL(currentCellChanged(int,int,int,int)),this,SLOT(currentCellChanged(int,int,int,int)));
        
        void MainWindow::nextMonth()
        {
            date_selected = date_selected.addDays(30);  
        }
        
        void MainWindow::currentCellChanged(int cr, int cc, int pr, int pc)
        {
            Q_UNUSED(pr);
            Q_UNUSED(pc);
            qDebug() << cr << cc;   
            CalendarDay *calendarDay = (CalendarDay*)(ui->tableWidget->cellWidget(cr,cc));
            date_selected = calendarDay->date;
            qDebug() << date_selected;   
        }
        ```

        https://github.com/sonichy

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Because you are accessing an invalid cell. And since you are using a C style cast, you are just getting a pointer to an invalid location.

          Use qobject_cast when dealing with QObject based classes and check that the returned pointer is not zero.

          Also add sanity checks for the index you are getting.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved