How to extract a resource from qrc (Solved)
-
Resources are completely transparent to the application and they might be treated as regular files, for example for copying (see previous post). The only restriction is that they are read-only, both the files itself (you cannot modify them) and the directory strucuture they are contained in (you cannot add or remove files to or from a resource collection).
-
@pkj__
I did as you said but I cannot write a QT resource file to a directory-structure-path.
Here is my code:#include <QCoreApplication> #include <QFile> #include <QString> #include <QDebug> #include <QTextStream> #include <iostream> using namespace std; void read(QString filename) { QFile file(filename); if(!file.open(QFile::ReadOnly | QFile::Text)) { qDebug() << " Could not open the file for reading"; return; } QTextStream in(&file); QString myText = in.readAll(); // put QString into qDebug stream qDebug() << myText; file.close(); } int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); read(":/resources/hello.pro"); bool status = QFile::copy(":/resources/hello.pro" , "~/abc/hel.pro"); if(status) { cout << "Success" << endl; } else { cout << "Failed" << endl; } return 0; }
Could you help me why I am getting Failed. I am expecting that I will create a new folder named abc inside the current directory and copy the resource file into that.
Thank and best regards.Thanh C. Tran
-
@thanhxp
Hi
Copy will not make a new folder
You must do that yourself
QDir().mkdir("~/abc");Update:
https://forum.qt.io/topic/72915/copy-qt-resource-file-into-filesystem/2 -