I am trying to make a list of QFiles, I went for the QList approach but am not sure if it is good approach or not.
I write this code but it fails to build!
QList<QFile> filesList;
QFile file_1(QString("path/to/file_1"));
QFile file_2(QString("path/to/file_2"));
filesList.append(file_1);
filesList.append(file_2);
for(auto& file : filesList){
if(!file.open(QIODevice::ReadOnly)){
qDebug() << "file is not open.";
}
}
The build failed with this error:
error: ‘QFile::QFile(const QFile&)’ is private within this context
if (QTypeInfo<T>::isLarge || QTypeInfo<T>::isStatic) n->v = new T(t);
^~~~~~~~
Is it good to use QList approach of making a list of files to use later? if so, how to fix my code ?
>Solution :
Why are you trying to create a list of QFile? Perhaps you can just store QString paths and then create QFile when needed:
QVector<QString> filePathsList;
filePathsList << QStringLiteral("path/to/file_1"));
filePathsList << QStringLiteral("path/to/file_2"));
for (auto &filePath : qAsConst(filePathsList)) {
QFile file(filePath);
if (!file.open(QIODevice::ReadOnly)) {
qDebug() << "file is not open.";
}
}