如何使用 setName/getName 方法的成员命名文件来设置 saveFile 方法的输出文件名。QString nomeFile 在 file.h 中是私有的 我创建的文件返回以下错误
QFSFileEngine::open: 未指定文件名
对话框.cpp
nomeFile="abcd"; // private: QString nomeFile; in dialog.h
file ogg1;
ogg1.setName(nomeFile);
f.cpp
file ogg2;
ogg2.saveFile();
文件.cpp
/* COSTRUTTORE */
a::a()
{
}
/* DISTRUTTORE */
a::~a()
{
}
void a::setName(QString _nomeFile)
{
nomeFile="C:\\Users\\MDN\\Documents\\A\\" + _nomeFile + ".txt";
if(!nomeFile.isEmpty())
{
QFile::remove(nomeFile);
}
}
QString a::getName()
{
return nomeFile;
}
void a::saveFile()
{
QFile file(nomeFile);
if (file.open(QIODevice::Append | QIODevice::WriteOnly | QIODevice::Text)
{
QTextStream stream(&file);
stream << "File salvato correttamente";
stream << ".....";
stream << ".....";
}
}