这是一段将QTableWidget里的数据保存为txt文本的代码,基本可以实现功能,
但是每次点完保存以后会弹出工程.exe已停止工作,关闭程序的对话框,我不知道为什么???
是程序缺少什么吗???求解答
{
curFile = tr("smart.txt");
setWindowTitle(curFile);
QString fileName = QFileDialog::getSaveFileName(this,tr("另存为"),curFile);
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
{
QMessageBox::information(NULL, tr("提示信息:"), tr("文件打开失败!"));
return;
}
QTextStream out(&file);
for (int i = 0; i < 30; i++)
{
if (Smart_Table->item(i,0)->text()!= "")
{
#if 1
QString str;
str.sprintf("%s %-30s %-7s %-6s %-7s %-7s %-30s",
(Smart_Table->item(i,0)->text().toLatin1().data()),
(Smart_Table->item(i,1)->text().toLatin1().data()),
(Smart_Table->item(i,2)->text().toLatin1().data()),
(Smart_Table->item(i,3)->text().toLatin1().data()),
(Smart_Table->item(i,4)->text().toLatin1().data()),
(Smart_Table->item(i,5)->text().toLatin1().data()),
(Smart_Table->item(i,6)->text().toLatin1().data())
);
out<<str<<endl;
#endif
}
}
curFile = QFileInfo(fileName).canonicalFilePath();
file.close();
}