How to solve TypeError: Failed to fetch in Qt for WebAssembly?
How to solve TypeError: Failed to fetch in Qt for WebAssembly?
我正在尝试 运行 我的 Qt 程序在浏览器中使用 WebAssembly。我按照指南进行操作,最终获得了 .html、.js 和 .wasm 文件。但是,当我尝试通过“双击”运行 index.html 文件时,出现上述错误。当我 运行 使用 em运行 --browser=chrome index.html 时,它工作正常。我该如何解决这个问题?
编辑:
我查看了控制台错误并得到了这个:Fetch API cannot load file:///home/siya/QtProjects/test/NotepadApplication.js。 URL 方案“文件”不受支持。
编辑 2:这是 qtloader.js:249:
的片段
247 function fetchResource(filePath) {
248 var fullPath = config.path + filePath;
249 return fetch(fullPath).then(function(response) {
250 if (!response.ok) {
251 self.error = response.status + " " + response.statusText + " " + response.url;
252 setStatus("Error");
253 return Promise.reject(self.error)
254 } else {
255 return response;
256 }
257 });
258 }
事实证明这种行为是预期的:出于安全原因,Google Chrome 等浏览器禁止从文件中读取。将其上传到在线服务器即可。
我正在尝试 运行 我的 Qt 程序在浏览器中使用 WebAssembly。我按照指南进行操作,最终获得了 .html、.js 和 .wasm 文件。但是,当我尝试通过“双击”运行 index.html 文件时,出现上述错误。当我 运行 使用 em运行 --browser=chrome index.html 时,它工作正常。我该如何解决这个问题?
编辑: 我查看了控制台错误并得到了这个:Fetch API cannot load file:///home/siya/QtProjects/test/NotepadApplication.js。 URL 方案“文件”不受支持。
编辑 2:这是 qtloader.js:249:
的片段247 function fetchResource(filePath) {
248 var fullPath = config.path + filePath;
249 return fetch(fullPath).then(function(response) {
250 if (!response.ok) {
251 self.error = response.status + " " + response.statusText + " " + response.url;
252 setStatus("Error");
253 return Promise.reject(self.error)
254 } else {
255 return response;
256 }
257 });
258 }
事实证明这种行为是预期的:出于安全原因,Google Chrome 等浏览器禁止从文件中读取。将其上传到在线服务器即可。