1

I have the following:

QString themePath(":/themes/");

std::vector<QString> resourcePaths;
resourcePaths.push_back(QString("html/details.html"));

std::vector<QFile> resources;
for (std::vector<QString>::iterator it = resourcePaths.begin(); it != resourcePaths.end(); ++it) {
    QString path = QString("%1%2/%3").arg(themePath, THEME, *it);
    QFile resource(path);
    resources.push_back(resource);
}

gives me the following error: error: 'QFile::QFile(const QFile&)' is private.

I get the same error if I use QList instead of std::vector.

Thank you for your attention.

3
  • 1
    You cannot copy QObjects. You could use a pointer or better: smart pointer (QScopedPointer, QSharedPointer, QPointer, etc based on your use case). Also, I would not mix std::vector into this. Why not use QList with foreach? You could also just have a QStringList for the paths here. It is hard to tell the best advise without more context. Commented Nov 12, 2013 at 18:11
  • Thank you for your response. Can you give me an example with a smart pointer? I'm interested to see what you meant Commented Nov 12, 2013 at 18:24
  • 1
    std::vector<QScopedPointer<QFile> > resources; ... QScopedPointer<QFile> resource(new QFile(path)); resources.push_back(resource); // Replace QScopedPointer with whatever smart pointer you need Commented Nov 12, 2013 at 18:28

1 Answer 1

1

The problem, is that you use QFile values in the container which implicitly perform copying of items with using the copy constructor which is private member function of QFile class. The compiler tells you that. To solve this you can try to simply store QFile pointers instead.

Sign up to request clarification or add additional context in comments.

2 Comments

can you give me an example?
@TrevorDonahue: std::vector<QFile*> resources; ... QFile *resource = new QFile(path); resources.push_back(resource); He means that, just not careful enough to give a fully comprehensive answer at first. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.