C++ qrc file access
Unsolved
General and Desktop
-
Just want to clarify a detail here: with the
FileIO::read(const QString& Url)
method below, if I use a qrc path, I get an error. If I use a relative path (";/") it works. I didn't set a prefix for the qrc resources – I just use the default.Can someone explain (for my Qt fatigued brain) what the difference here is and why the qrc path doesn't resolve to ":/"
thanks!
var readResult = fileio.read("qrc:/test.json");
// this doesn't workvar readResult = fileio.read(":/test.json");
// this doesQString FileIO::read(const QString& Url) { m_source = Url; emit error(m_source); if (m_source.isEmpty()){ emit error("source is empty"); return QString(); } QFile file(m_source); QString fileContent; if ( file.open(QIODevice::ReadOnly) ) { QString line; QTextStream t( &file ); t.setCodec("UTF-8"); do { line = t.readLine(); fileContent += line; } while (!line.isNull()); file.close(); } else { emit error("Unable to open the file"); return QString(); } return fileContent; }
-
@TOMATO_QT said:
I did wonder the same thing
and it seems to me that C++ use the ":/"
and QML
likes the "qrc:/"
I have seen code do
view->setUrl(QUrl("qrc:/dial.qml"));So to make it ":/" it might need a to go though QUrl ?
Not tested, just pure speculation.