qmluic
supports a tiny subset of QML and JavaScript/TypeScript syntax. The
language is syntactically compatible with QML/JS so you can use Qt Creator
for editing, but the semantics is diverged from JavaScript.
Notable differences are:
- No implicit type conversion (except for object upcasting on assignment.)
- Integer and floating point are distinct types.
- Integer division returns an integer.
Constant expression will be embed in the .ui
XML file.
windowTitle: qsTr("Hello world!")
If the right-hand expression isn't constant, it will be automatically re-evaluated when the underlying value changes.
QComboBox { id: edit }
QStackedWidget { id: stack; currentIndex: edit.currentIndex }
Under the hood, this will be translated to the following signal/slot connection.
connect(edit, &QComboBox::currentIndexChanged, root,
[]() { stack->setCurrentIndex(edit->currentIndex()); });
Signal callback can be attached by on<Signal>
.
QDialogButtonBox {
onAccepted: root.accept()
onRejected: root.reject()
}
In order to take signal arguments, wrap the callback statements with
function() { ... }
. Unlike QtQuick/QML, type annotation is mandatory.
onToggled: function(checked: bool) {
}
TODO: metatype_tweak.rs
In addition to Q_OBJECT
/Q_GADGET
classes and Q_ENUM
s, the following
types are defined.
bool
double
/qreal
int
uint
QBrush
QColor
QCursor
QIcon
QPalette
QString
QStringList
(aliased to a list ofQString
)QVariant
void
Not all types are usable in dynamic expression context. For example, there's
no QColor
constructor yet.
QObject
-derived objects are passed by pointer.
- Unary arithmetic:
+
,-
- Unary bitwise:
~
- Unary logical:
!
- Binary arithmetic:
+
,-
,*
,/
,%
- Binary bitwise:
&
,^
,|
- Shift:
>>
,<<
- Binary logical:
&&
,||
- Comparison:
==
,!=
,<
,<=
,>
,>=
- List subscript:
<list>[<index>]
(no bounds check) - Type cast:
<value> as <type>
- numeric cast amongst
int
/uint
/double
enum
to integerbool
to integer- discarding result:
<value> as void
- extract stored value from
QVariant
- TODO:
qobject_cast
for downcasting will be added later
- numeric cast amongst
- Ternary:
... ? ... : ...
Operands are statically type checked. <string> + <int>
is invalid for
example.
Strict comparison operators, ===
and !==
, are aliased to ==
and !=
respectively. There are no lax comparison operators.
Functions:
Math.max(a, b)
,Math.min(a, b)
console.log()
,.debug()
,.info()
,.warn()
,.error()
qsTr()
Methods:
QList<T>::isEmpty()
QString::arg()
QString::isEmpty()
let
/const
(type annotation or initial value is required)if
/else
switch
/case
/default
/break
(case expression is tested by==
operator)return
No loop statement is available.