hi
I'm coding spreadsheet ... so i am using QTableWidget in my program
I coded a func for saving table's items ...
i have a structure here :
struct cells
{
int r;
int c;
};
struct cells
{
int r;
int c;
QString text;
};
To copy to clipboard, switch view to plain text mode
in this func I want to save items
reads items ... copies data into a cells object :
void MainWindow::on_save_clicked()
{
cells *temp;
fstream file;
file.open("test_3.txt",ios::out |ios::binary |ios::trunc);
if(file)
{
for(int i=0;i<ui->tableWidget->columnCount();i++)
for(int j=0;j<ui->tableWidget->rowCount()-1;j++)
{
temp=new cells;
temp->c=i;
temp->r=j;
temp->text.append("ui->tableWidget->item(j,i)->text()");
file.write(reinterpret_cast<char* >(temp),sizeof(cells));
delete temp;
}
file.close();
}
else
this->close();
}
void MainWindow::on_save_clicked()
{
cells *temp;
fstream file;
file.open("test_3.txt",ios::out |ios::binary |ios::trunc);
if(file)
{
for(int i=0;i<ui->tableWidget->columnCount();i++)
for(int j=0;j<ui->tableWidget->rowCount()-1;j++)
{
temp=new cells;
temp->c=i;
temp->r=j;
temp->text.append("ui->tableWidget->item(j,i)->text()");
file.write(reinterpret_cast<char* >(temp),sizeof(cells));
delete temp;
}
file.close();
}
else
this->close();
}
To copy to clipboard, switch view to plain text mode
my program stops working in this line and when i debug it , it shows me the "segmentation fault" from my OS , this line :
temp->text.append("ui->tableWidget->item(j,i)->text()");
temp->text.append("ui->tableWidget->item(j,i)->text()");
To copy to clipboard, switch view to plain text mode
why ?
what's it's problem with text function of QString class here ?
thanks
Bookmarks