How to set QDate more than once ?
-
Hi
That sounds odd.
Unless QDate1 and QDate2 are pointers, then it seems almost impossible.Can you show the actual code ?
-
Hi
That sounds odd.
Unless QDate1 and QDate2 are pointers, then it seems almost impossible.Can you show the actual code ?
@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; } ``` -
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.