PDA

View Full Version : hi everyone.. Error filingl the data into the spreadsheet.



harshitha1234
25th April 2013, 18:40
i use the following to fill the data into the spreadsheet. the fill_dataNC function is called every time user clicks ok button after giving input.
but it takes only the first 2 to 4 inputs and den gives this error --

*** glibc detected *** ./shm1: malloc(): memory corruption (fast): 0x00000000011e3f11 ***

please help me solve this

void Spreadsheet::clear()
{

setRowCount(0);
setColumnCount(0);
setRowCount(RowCount);
setColumnCount(ColumnCount);

tableWidget = new QTableWidget(0, ColumnCount);
for (int i = 0; i < RowCount; ++i)
{
int row = tableWidget->rowCount();
tableWidget->insertRow(row);
}

setCurrentCell(0,0);
}

void Spreadsheet::fill_dataNC()
{

int rowNo = ip3; // user input
int colNo = ip1; // user input
int sampRa = ip2; // user input
if(flag == 0)
{
while(rowNo < RowCount)
{
setItem(rowNo,colNo,new QTableWidgetItem(QString::number(a16bit, 16) + QChar('x')));
item(rowNo,colNo)->setBackgroundColor(Qt::lightGray);
wordCount++;
emptyCount--;
rowNo = rowNo + sampRa;
}
}
else
{
while(rowNo < RowCount)
{
while(colNo < ColumnCount)
{
setItem(rowNo,colNo,new QTableWidgetItem(QString::number(a16bit, 16) + QChar('x')));
item(rowNo,colNo)->setBackgroundColor(Qt::cyan);
wordCount++;
emptyCount--;
colNo = colNo + sampRa;
}
rowNo++;
}
}

}

Santosh Reddy
25th April 2013, 19:24
Information is not sufficient, with the available information, this is what I can tell

First use [CODE]...[\CODE] (change \ to /) tags for posting code.

What is Spreadsheet, I assume QTableWidget derived class?
At which line does the error occur, I assume it is setItem(). When you call setItem() you need make sure that the particular row exists in the table.

Eg: If you want to insert into 10th row, you have to make sure (insert required rows) that 10th (index 9) row exists in the table else program may crash.

BTW: You should have posted this in Qt Newbie forum