Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to make a list(QList) of QFiles? and how it works?

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 ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.";
    }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading