Hi,
Thanks for the responses. I did some debugging and have been able to avoid the infinite loop however, I have run into the below mentioned issues.
\ I have found that there is a signal called cellchanged() that emits changes made onto the table to a custom slot called OnEditView().
This function looks for the changed item using the code above.
The issue is that I do not want this signal to be emitted upon adding new rows to the tableWidget. If I delete a row and add a new one, I do not get the following error; it occurs only upon trying to add a new row to the table.
Exception at 0x657aa87c, code:0xc0000005:read access violation at:0x0, flags=0x0 (first chance)
However, this signal is meant to be emitted only when an existing item is modified, but it seems to be emitted upon trying to add a new row as well. That is where the problem is.
I used a similar signal called itemchanged() then too I face the same issue.
But the same signal when used with QTAbleView seems to work fine.
The following is EditView
void MainWindow::onEditView()
{//Capturing the changed value from the table
QString changed_t
=ui
->tableWidget
->currentItem
()->text
();
qDebug()<<changed_t<<__FUNCTION__;
//Obtaining the row and column values for the edited item
int r_id=ui->tableWidget->currentItem()->row();
int c_id=ui->tableWidget->currentItem()->column();
int line_count=0;
//Changing the particular value in the file
QFile file_r
("address1.txt");
if(!file_r.exists()){
return;
}
while(!file_r.atEnd()){
line=line.simplified();
line_data
=line.
split(";",
QString::SkipEmptyParts);
for(int j=0;j<line_data.size();j++){
if((j==c_id)&&(line_count==r_id)){
line_data.replace(j,changed_t);
//qDebug()<<"split: "<<line_data;
line.clear();
if(j==line_data.size()-1){
line_app.append(line_data.at(j)+"\n");
}
else{
line_app.append(line_data.at(j)+";");
}
}
else{
if(j==line_data.size()-1){
line_app.append(line_data.at(j)+"\n");
}
else{
line_app.append(line_data.at(j)+";");
}
}
}
//qDebug()<<line;
line_count++;
}
file_r.resize(0);
wstream<<line_app;
file_r.close();
}
}
void MainWindow::onEditView()
{//Capturing the changed value from the table
QString changed_t=ui->tableWidget->currentItem()->text();
qDebug()<<changed_t<<__FUNCTION__;
//Obtaining the row and column values for the edited item
int r_id=ui->tableWidget->currentItem()->row();
int c_id=ui->tableWidget->currentItem()->column();
int line_count=0;
//Changing the particular value in the file
QFile file_r("address1.txt");
if(!file_r.exists()){
return;
}
QString line_app;
QTextStream wstream(&file_r);
if(file_r.open(QIODevice::ReadWrite)){
while(!file_r.atEnd()){
QStringList line_data;
QString line=file_r.readLine();
line=line.simplified();
line_data=line.split(";",QString::SkipEmptyParts);
for(int j=0;j<line_data.size();j++){
if((j==c_id)&&(line_count==r_id)){
line_data.replace(j,changed_t);
//qDebug()<<"split: "<<line_data;
line.clear();
if(j==line_data.size()-1){
line_app.append(line_data.at(j)+"\n");
}
else{
line_app.append(line_data.at(j)+";");
}
}
else{
if(j==line_data.size()-1){
line_app.append(line_data.at(j)+"\n");
}
else{
line_app.append(line_data.at(j)+";");
}
}
}
//qDebug()<<line;
line_count++;
}
file_r.resize(0);
wstream<<line_app;
file_r.close();
}
}
To copy to clipboard, switch view to plain text mode
Any advice please
Bookmarks