PDA

View Full Version : error: ‘QFile::QFile(const QFile&)’ is private by using a foreach



criskross
6th May 2013, 02:18
Hey guys,

I got this error message by trying to use my code under linux.



QStringList files = searchFiles(filepath);
foreach(QFile foundFile, files) {
// operations...
}



Does anyone know a reason for that. I really don't want to change all of code.

thx in advance

ChrisW67
6th May 2013, 03:10
The error message is self explanatory. You cannot copy a QFile (or any other QObject), and the copy constructor has been made private to enforce this. foreach() will be implicitly converting each string in your list to a QFile in a way that tries to invoke the copy constructor, e.g.


QFile foundFile = QString("test");

Your loop needs to be:


foreach(const QString &name, files) {
QFile foundFile(name);
// operations...
}

criskross
6th May 2013, 09:06
Ok nice that works. Thx :)