-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Cross-Platform Development with Qt 6 and Modern C++
By :
QML has a good integration with JS and uses JavaScript Object Notation (JSON)-like syntaxes, allowing expressions and methods to be defined as JS functions. It also permits developers to import JS files and use the existing functionality. The QML engine provides a JS environment that has some limitations compared to the JS environment provided by a web browser. The logic for a Qt Quick application can be defined in the JS. The JS code can be written inline inside the QML file, or in a separate JS file.
Let's look at how to use inline JS inside a QML document. The following example demonstrates the btnClicked() inline JS function. The method is called when the Button control is clicked:
import QtQuick
import QtQuick.Window
import QtQuick.Controls
Window {
width: 640; height: 480;
visible: true
title: qsTr("QML JS integration")
function btnClicked...