PDA

View Full Version : Why my for loop always gets SIGSEGV in a QTableWidget?



schinkengott
15th June 2015, 15:00
hey guys, im programming a little programm with QTableWidget.
But everytime i work with two for loops to get empy Cells etc, my programm crashes with SIGSEGV, i know what it is but i do not know why im getting it.
Example:
I'm trying to search for empty cells:


void MainWindow::checkEmpty()
{
for(int row=0;row<getMaxRow();row++) //getMaxRow returns the rowCount
{
for(int col=0;col<getMaxCol();col++)
{
if(table->item(row,col)->text().isEmpty())
{
QTableWidgetItem *item = new QTableWidgetItem;
item->setText("");
table->setItem(row,col, item);
}
}
}
}
im in my table memory, but everything i launch it my programm crashes..
many times im using this loops and everytime it kills my programm.
i need to search for empy cells, to fill it with "" or a "0", because other functions will crash if in a cell is really nothing.
can someone help me? i have to fill new cells with something like a space or a "0".

Lesiok
15th June 2015, 15:56
QTableWidget::item (in line 7) may return 0. I think that it should be :
if(table->item(row,col) == 0)

schinkengott
15th June 2015, 16:06
thanks, but im searching for empty cells, and not cells with a 0 inside it.
i want to get these empty cells filled with a 0

EDIT: oh i saw what you ment!
it works, thank you!!