change to asset read

This commit is contained in:
王劲鹏
2021-06-10 11:05:31 +08:00
committed by osborn
parent 0b4b9c2ed6
commit e6cff004d0
7 changed files with 30 additions and 7 deletions

View File

@@ -10,7 +10,7 @@ private:
QString result;
public:
std::function<void()> resultCallback;
std::function<void()> resultCallback = [] {};
std::function<void()> exceptionCallback;
std::function<void()> finishCallback;

View File

@@ -12,8 +12,12 @@ std::shared_ptr<DoricAsyncResult> DoricAssetJSLoader::request(QString source) {
QString protocol = "assets://";
QString assetPath = source.mid(protocol.length());
QString script = DoricUtils::readAssetFile("/" + assetPath);
std::shared_ptr<DoricAsyncResult> asyncResult =
std::make_shared<DoricAsyncResult>();
asyncResult->setResult(script);
return asyncResult;
}

View File

@@ -24,6 +24,19 @@ public:
return content;
}
static QString readAssetFile(QString resourcePath) {
QResource resource(":" + resourcePath);
QFile *file = new QFile(resource.fileName());
file->open(QFile::ReadOnly | QFile::Text);
QTextStream in(file);
in.setCodec("UTF-8");
QString content = in.readAll();
file->close();
delete file;
return content;
}
template <typename Base, typename T>
static inline bool instanceof (const T *) {
return std::is_base_of<Base, T>::value;