https://github.com/grassator/qml-commonjs
Experiment in adding CommonJS support to QML.
https://github.com/grassator/qml-commonjs
Last synced: 10 months ago
JSON representation
Experiment in adding CommonJS support to QML.
- Host: GitHub
- URL: https://github.com/grassator/qml-commonjs
- Owner: grassator
- License: mit
- Created: 2013-12-23T09:28:22.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2017-08-26T10:39:47.000Z (over 8 years ago)
- Last Synced: 2023-04-09T14:49:39.113Z (almost 3 years ago)
- Language: JavaScript
- Size: 241 KB
- Stars: 28
- Watchers: 8
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DISCONTINUED
> **Notice:** Unfortunately I can not commit to supporting and further development of this project. Please check [Quickly](https://github.com/quickly/quickly/) which provides similar, or better functionality. If you are still interested in becoming an owner / maintainer please submit an issue and I will get back to you.
# QML CommonJS
Experiment in adding CommonJS module support to QML.
## Changelog
### Version 0.2
* Fixed compatibility with Qt 5.4+ (see changes below for details).
* **CHANGED** paths for `CommonJS.require` calls from QML are now resolved relative to `QmlEngine::baseUrl()` because evaluating `Qt.resolvedUrl('.')` no longer works from CPP code for some reason.
* **CHANGED** evaluated module is now wrapped in an [IIFE](https://en.wikipedia.org/wiki/Immediately-invoked_function_expression) to avoid weird problem where function with a name same a property on a global object (e.g. `hasOwnProperty`) would result in an error.
### Version 0.1
* Full [modules](http://nodejs.org/api/modules.html) support
* `assert` module
* `setTimeout` / `clearTimeout` / `setInterval` / `clearInterval`
* experimental support for `util`, `events`, `path`, `url` and `querystring` modules.
When accessing top-level functions (like `setTimeout`) from QML, you have to use `CommonJS.` prefix because Qt doesn't allow defining global functions.
## Installation
* Make sure you have [Qt 5.4+](https://www.qt.io/) installed.
* Clone this repository.
* Then run `qmake && make && make install`
## Usage
After that you should be able to just import CommonJS as regular QML library and use it in your code:
```js
import CommonJS 0.2
import QtQuick 2.0
Rectangle {
Component.onCompleted: {
CommonJS.setTimeout(function(){
// built-in module
var example = CommonJS.require('path');
// relative to QML base url
var example = CommonJS.require('./example.js');
// relative to this file
var example = CommonJS.require(Qt.resolvedUrl('./example.js'));
});
}
}
```