问题
In one of my methods I need a QFile Object:
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)
{
...
}
}
The problem is the line I marked with "// ERROR LINE HERE!". When compiling I get the error message: QFile :: QFile (const QFile &) 'is private. I don't understand this, because in the QFile documentary the function is declared as public. Can someone tell me how to fix that?
回答1:
Replace:
QFile GEO = (loadedDirectory + "/1_geo.m4");
with this line:
QFile GEO(loadedDirectory + "/1_geo.m4");
回答2:
what you did here
QFile GEO = (loadedDirectory + "/1_geo.m4");
was using the assignment operator to create a QFile from a path, which is not possible
you should use the constructor like this
QFile GEO(loadedDirectory + "/1_geo.m4");
回答3:
Remove the equals sign to do direct-initialization.
来源:https://stackoverflow.com/questions/9601821/qfileqfile-function-error-qfile-qfile-const-qfile-is-private