qt中fstream文件流打不开文件怎么办法,qt中自己的文件流没用过
当前工程目录中有一个文本文件但是打不开
看看是不是路径不对,建议用绝对路径。或者是权限不足。
不知道你这个问题是否已经解决, 如果还没有解决的话:先用QFileDialog获取文件路径,之后就是常规的文件读取了
void MainWindow::on_action_openFile_triggered()
{
QString path = QFileDialog::getOpenFileName(this,
tr("Open File"),
".",
tr("Text Files(*.txt)"));
if(!path.isEmpty())
{
QFile file(path);
file.open(QIODevice::WriteOnly | QIODevice::Text);
elementList.clear();
QTextStream in(&file);
int totNum;
in >> totNum;
for(int i = 0; i < totNum; i++)
{
paintObject tempObject;
in >> tempObject.type >> tempObject.mouseX >> tempObject.mouseY >> tempObject.rota;
elementList.push_back(tempObject);
}
file.close();
update();
}
else
{
QMessageBox::warning(this, tr("Path"),
tr("You did not select any file."));
}
}