Node-Qt provides native bindings to the Qt library as a Node.js addon. The focus is on GUI bindings; there is no need to duplicate the functionality of the Node API and its modules.
We try to follow Qt's API as closely as possible, but there is some changes due to differences between nodejs and c++ and sometimes quirks are inevitable (for example, virtual methods that handle events are translated into callback setters). See the header files in src/
for a list of available bindings, and comments in .cc
files for possible API differences.
Supported platforms: Mac OS X | Windows | Linux
Ever wanted to create native apps directly from Node?
var qt = require('..'),
app = new qt.QApplication;
// Prevent objects from being GC'd
global.app = app;
var hello = new qt.QPushButton('Hello World', function() {
console.log('hi');
});
hello.setGeometry(200,200,200,200);
hello.show();
// Start application
app.exec();
From your project directory, run (see below for requirements):
$ npm install node-qt
Alternatively, to use the latest development version from Github:
$ npm install git://github.com/dubcanada/node-qt.git
This will download and build Node-Qt in node_modules/
. Then create a new file, say helloworld.js
, copy the example above and run Node as usual:
$ node helloworld
See the examples/ directory for other simple use cases.
Modules | Completed | Total |
---|---|---|
QtCore | 1 | 213 |
QtGUI | 0 | 207 |
QtMultimedia | 0 | 82 |
QtWidgets | 2 | 202 |
Node-Qt was designed to build seamlessly with minimal dependencies on most platforms. The necessary platform-dependent Qt binaries are bundled with the module (due to heterogeneous dependencies, Linux is an exception).
For all platforms: Node >= 0.10.29
- Mac: Python, Make, and GCC.
- Windows: Python and MSVC++ (either free or commercial).
- Linux: Python, Make, GCC, pkg-config, and Qt 5.3+.
To download and build the development version:
$ git clone git://github.com/dubcanada/node-qt.git
$ cd node-qt
$ npm install
Run node tools/gen.js
for list of options.
- Create your files (e.g.
qclass.h
,qclass.cc
) from the provided templatessrc/template.h
,src/template.cc
qclass.*
: search and replace all occurrences of__Template__
,__TEMPLATE__
, and__template__
with the corresponding class namenode-qt.gyp
: Add qclass.cc to sources listqt.cc
: Includeqclass.h
qt.cc
: AddQClass::Initialize()
toInitialize()
qclass.h
: Declare static method as perExample()
method intemplate.h
qclass.cc
: Implement method as perExample()
intemplate.cc
qclass.cc
: Expose method to JavaScript viatpl->PrototypeTemplate()
call inInitialize()
. Again see template.cc.
Add lines too binding.gyp and qt.cc (see each file for examples).