Skip to content

Commit

Permalink
Fix loading qmldir file when current dir is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelvasev committed May 30, 2015
1 parent 7302347 commit 9639deb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/import.js
Expand Up @@ -75,6 +75,7 @@ function parseQML(file) {
* @return {mixed} String of contents or false in errors.
*/
getUrlContents = function (url,skipErrorLogging) {
//console.log("getUrlContents",url);
var xhr = new XMLHttpRequest();
xhr.open("GET", url, false);
try {
Expand Down Expand Up @@ -130,8 +131,11 @@ readQmlDir = function (url) {
// case 2 - replace github.com/user/repo/tree/master/dir -> github.com/user/repo/master/dir, because we then get files, not tree
url = url.replace("/tree/master/","/master/");
}

var qmldir = getUrlContents(url + "/qmldir", true), // loading url contents with skipping errors

// in case 'url' is empty, do not attach /
var qmldirFileUrl = url.length > 0 ? (url + "/qmldir") : "qmldir";

var qmldir = getUrlContents( qmldirFileUrl, true), // loading url contents with skipping errors
lines,
line,
internals = {},
Expand Down
9 changes: 7 additions & 2 deletions src/qtcore.js
Expand Up @@ -186,7 +186,7 @@ Qt.createComponent = function(name, executionContext)
}

var file = nameIsUrl ? name : engine.$basePath + name;

var src = getUrlContents(file,true);

// if failed to load, and provided name is not direct url, try to load from dirs in importPathList()
Expand All @@ -210,6 +210,7 @@ Qt.createComponent = function(name, executionContext)

var component = new QMLComponent({ object: tree, context: executionContext });
component.$basePath = engine.extractBasePath( file );

component.$imports = tree.$imports;
component.$file = file; // just for debugging

Expand Down Expand Up @@ -1371,7 +1372,11 @@ QMLComponent.prototype.createObject = function(parent, properties) {
engine.operationState = QMLOperationState.Init;

// change base path to current component base path
var bp = engine.$basePath; engine.$basePath = this.$basePath ? this.$basePath : engine.$basePath;

var bp = engine.$basePath; // this is old engine.$basePath = this.$basePath ? this.$basePath : engine.$basePath;

// the logic of finding basepath is so interesting ...
engine.$basePath = this.$basePath || (this.$context ? this.$context.$basePath : null) || engine.$basePath;

var item = construct({
object: this.$metaObject,
Expand Down

0 comments on commit 9639deb

Please sign in to comment.