在我的一个方法中,我需要一个QFile对象:
void GUIsubclassKuehniGUI::LoadDirectory()
{
QString loadedDirectory = QFileDialog::getExistingDirectory(this,
"/home",tr("Create Directory"),
QFileDialog::DontResolveSymlinks);
ui.PathDirectory -> setText(loadedDirectory);
QFileInfo GeoDat1 = loadedDirectory + "/1_geo.m4";
QFileInfo GeoDat2 = loadedDirectory + "/2_geo.m4";
QString Value;
if (GeoDat1.exists() == true)
{
QFile GEO = (loadedDirectory + "/1_geo.m4"); // ERROR LINE HERE!
if(GEO.open(QIODevice::ReadOnly | QIODevice::Text))
{
QTextStream Stream (&GEO);
QString Text;
do
{
Text = Stream.readLine();
QString startWith = "start";
QString endWith = "stop" ;
int start = Text.indexOf(startWith, 0, Qt::CaseInsensitive);
int end = Text.indexOf(endWith, Qt::CaseInsensitive);
if (start != -1)
Value = Text.mid(start + startWith.length(), end - ( start + startWith.length() ) );
double ValueNumber = Value.toDouble();
ValueNumber = ui.ValueLineEdit->value();
}
while(!Text.isNull());
GEO.close();
}
}
else if (GeoDat2.exists() == true)
{
...
}
}
问题是我用“// ERROR LINE HERE!”标记的行。编译时我收到错误消息: QFile :: QFile(const QFile&)'是私有的。我不明白这一点,因为在QFile纪录片中,该函数被声明为public。 有人能告诉我如何解决这个问题吗?
答案 0 :(得分:6)
替换:
QFile GEO = (loadedDirectory + "/1_geo.m4");
这一行:
QFile GEO(loadedDirectory + "/1_geo.m4");
答案 1 :(得分:3)
QFile GEO = (loadedDirectory + "/1_geo.m4");
使用赋值运算符从路径创建QFile,这是不可能的
你应该使用像这样的构造函数
QFile GEO(loadedDirectory + "/1_geo.m4");
答案 2 :(得分:2)
删除等号以执行直接初始化。