### Instantiate Project Environment Source: https://juliagraphics.github.io/QML.jl/dev/developer Navigates to the QML.jl folder and starts Julia with the project environment. Then, it installs all the necessary project dependencies. ```julia using Pkg Pkg.instantiate() ``` -------------------------------- ### Load QML from a Julia Module Source: https://juliagraphics.github.io/QML.jl/dev This example demonstrates how to load a QML file from within a Julia module, ensuring proper function registration and context property setup. It requires a corresponding QML file in a subdirectory. ```julia module QmlModuleTest using QML # absolute path in case working dir is overridden const qml_file = joinpath(dirname(@__FILE__), "qml", "frommodule.qml") # Propertymap is a pointer, so it needs to be a function and not a const value props() = JuliaPropertyMap( "hi" => "Hi", ) world() = " world!" # Convenience function to call all relevant function macros function define_funcs() @qmlfunction world end function main() define_funcs() loadqml(qml_file; props=props()) exec() end end # module QmlModuleTest ``` -------------------------------- ### Load and Create QML Component Source: https://juliagraphics.github.io/QML.jl/dev Loads QML code into a QQmlComponent and then creates an instance of it. This example uses a simple ApplicationWindow with a Text element that displays a context property. ```julia component = QQmlComponent(an_engine); set_data(component, QByteArray(""" import QtQuick import QtQuick.Controls ApplicationWindow { visible: true Rectangle { Text { text: greeting } Timer { running: true; repeat: false onTriggered: Qt.exit(0) } } } """), QUrl()) create(component, qmlcontext()) exec() ``` -------------------------------- ### Initialize QML Engine and Get Root Context Source: https://juliagraphics.github.io/QML.jl/dev Initializes a QML engine and retrieves its root context. This is a prerequisite for setting context properties and loading QML components. ```julia using QML an_engine = init_qmlengine(); context = root_context(an_engine); ``` -------------------------------- ### Set and Get Context Property Source: https://juliagraphics.github.io/QML.jl/dev Demonstrates setting a property in the QML context and then retrieving it. This allows passing data from Julia to QML. ```julia set_context_property(context, "greeting", "Hello, World!"); context_property(context, "greeting") ``` -------------------------------- ### QML.exec_async Source: https://juliagraphics.github.io/QML.jl/dev Starts the QML event loop asynchronously without blocking the main process, polling the QML interface periodically. ```APIDOC ## QML.exec_async ### Description Similar to `exec`, but does not block the main process. This method keeps the REPL active and periodically polls the QML interface for events using a timer within the Julia event loop. ### Function Signature ```julia function exec_async() ``` ### Usage Use this when you need to interact with QML without halting your Julia program's execution. ``` -------------------------------- ### Check Qt Prefix Path Source: https://juliagraphics.github.io/QML.jl/dev Verifies the Qt prefix path to ensure the correct Qt version is being used. This is useful for debugging installation issues. ```julia using QML isdir(qt_prefix_path()) ``` -------------------------------- ### Expand Dots Macro Example Source: https://juliagraphics.github.io/QML.jl/dev Demonstrates the usage of the `@expand_dots` macro to transform dot notation into function calls for nested object access. ```julia using QML QML.@expand_dots object_.field_ func ``` ```julia julia> using QML julia> @macroexpand QML.@expand_dots a.b.c.d f :(f(f(f(a, "b"), "c"), "d")) ``` -------------------------------- ### Display Image in QML with JuliaDisplay Source: https://juliagraphics.github.io/QML.jl/dev Demonstrates how to send images from Julia to a QML interface using the JuliaDisplay type. The display can be added using `pushdisplay!` or passed by value. This example shows defining a Julia function and calling it from QML to display a random grayscale image. ```julia using QML using Colors function simple_image(julia_display::JuliaDisplay) display(julia_display, Gray.(rand(50,50))) nothing end; @qmlfunction simple_image ``` ```qml import QtQuick import QtQuick.Controls import QtQuick.Layouts import jlqml ApplicationWindow { visible: true JuliaDisplay { id: julia_display width: 50 height: 50 Component.onCompleted: { Julia.simple_image(julia_display) } } Timer { interval: 2000; running: true; repeat: false onTriggered: Qt.exit(0) } } ``` -------------------------------- ### Add TestEnv Package Source: https://juliagraphics.github.io/QML.jl/dev/developer Installs the TestEnv package globally in Julia. This is a prerequisite for managing project environments. ```julia using Pkg Pkg.add("TestEnv") ``` -------------------------------- ### QML.root_context Source: https://juliagraphics.github.io/QML.jl/dev Gets the root context of a `QQmlEngine`. This context can be used to set and get properties, enabling data exchange between Julia and QML. ```APIDOC ## QML.root_context ### Description Get the context of `an_engine`. Equivalent to `QQmlEngine::rootContext`. Use `set_context_property` to modify the context. Use `context_property` to get a particular property. Use to get the context of an engine created with `init_qmlengine` before using `set_data` or from `engine`. ### Function Signature ``` root_context(an_engine::QQmlEngine) ``` ### Example ```julia using QML an_engine = init_qmlengine() context = root_context(an_engine) set_context_property(context, "greeting", "Hello, World!") context_property(context, "greeting") component = QQmlComponent(an_engine) set_data(component, QByteArray(""" import QtQuick import QtQuick.Controls ApplicationWindow { visible: true Rectangle { Text { text: greeting } Timer { running: true; repeat: false onTriggered: Qt.exit(0) } } } """), QUrl()) create(component, qmlcontext()) exec() ``` ``` -------------------------------- ### Set and Get QML Context Property Source: https://juliagraphics.github.io/QML.jl/dev Demonstrates setting a context property for a QML view and accessing it within the QML code. The `greeting` property is set in Julia and displayed in a QML `Text` element. ```qml import QtQuick import QtQuick.Controls Rectangle { Text { text: greeting } Timer { running: true; repeat: false onTriggered: parent.Window.window.close() } } ``` ```julia using QML mktempdir() do folder path = joinpath(folder, "main.qml") write(path, """ import QtQuick import QtQuick.Controls Rectangle { Text { text: greeting } Timer { running: true; repeat: false onTriggered: parent.Window.window.close() } } """) quick_view = init_qquickview() context = root_context(engine(quick_view)) set_context_property(context, "greeting", "Hello, World!") set_source(quick_view, QUrlFromLocalFile(path)) QML.show(quick_view) exec() end ``` -------------------------------- ### Get QML Content Item Source: https://juliagraphics.github.io/QML.jl/dev Retrieve the content item of a `QQuickView`. This is equivalent to `QQuickWindow::contentItem` and returns a `CxxPtr{QQuickItem}`. ```julia using QML using CxxWrap.CxxWrapCore: CxxPtr quick_view = mktempdir() do folder path = joinpath(folder, "main.qml") write(path, """ import QtQuick import QtQuick.Controls Rectangle { Timer { running: true; repeat: false onTriggered: Qt.exit(0) } } """) quick_view = init_qquickview() set_source(quick_view, QUrlFromLocalFile(path)) @assert content_item(quick_view) isa CxxPtr{QQuickItem} exec() end ``` -------------------------------- ### Build and Serve Documentation Locally Source: https://juliagraphics.github.io/QML.jl/dev/developer Builds and serves the QML.jl documentation locally using LiveServer.jl. Access the documentation via the provided localhost link. ```julia using LiveServer servedocs() ``` -------------------------------- ### Load and Execute QML with QQmlApplicationEngine Source: https://juliagraphics.github.io/QML.jl/dev Demonstrates loading a QML file using `QQmlApplicationEngine` and executing it. The engine's lifetime is managed by C++. ```julia using QML mktempdir() do folder path = joinpath(folder, "main.qml") write(path, """ import QtQuick import QtQuick.Controls ApplicationWindow { visible: true Text { text: greeting } Timer { running: true; repeat: false onTriggered: Qt.exit(0) } } """) loadqml(path; greeting = "Hello, World!") exec() end ``` -------------------------------- ### QML.init_qmlengine Source: https://juliagraphics.github.io/QML.jl/dev Initializes and returns a new QML engine. The context can be modified using root_context. ```APIDOC ## QML.init_qmlengine ### Description Creates and returns a new QML engine. You can modify the engine's context using `root_context`. This engine can then be used to create `QQmlComponent`s. See the example for `set_data` for usage. Alternatively, you can obtain the engine for an existing `QQuickView` using the `engine` function. ### Function Signature ```julia function init_qmlengine() ``` ### Returns * `QQmlEngine` - A newly created QML engine. ### Example (See example for `QML.set_data`) ``` -------------------------------- ### Display QML with QQuickView Source: https://juliagraphics.github.io/QML.jl/dev Demonstrates using `QQuickView` to display a QML file. `QQuickView` creates a window, so `ApplicationWindow` is not needed in the QML. ```julia using QML mktempdir() do folder path = joinpath(folder, "main.qml") write(path, """ import QtQuick import QtQuick.Controls Rectangle { Text { text: "Hello, World!" } Timer { running: true; repeat: false onTriggered: parent.Window.window.close() } } """) quick_view = init_qquickview() set_source(quick_view, QUrlFromLocalFile(path)) QML.show(quick_view) exec() end ``` -------------------------------- ### Create QML Component with QQmlComponent Source: https://juliagraphics.github.io/QML.jl/dev Shows how to create a QML component using `QQmlComponent`, set its data, create a window from it, and execute. ```julia using QML component = QQmlComponent(init_qmlengine()) set_data(component, QByteArray(""" import QtQuick import QtQuick.Controls ApplicationWindow { visible: true Rectangle { Text { text: "Hello, World!" } Timer { running: true; repeat: false onTriggered: Qt.exit(0) } } } """), QUrl()) create(component, qmlcontext()) exec() ``` -------------------------------- ### Load and Execute QML with Observables Source: https://juliagraphics.github.io/QML.jl/dev Loads a QML file and sets up an observable output. Includes a timer for doctests to set a default output and exit. ```julia using QML function loadqml_with_observables(path::String; output = 0.0) @qmlfunction isinteractive # For doctest loadqml(path; observables = JuliaPropertyMap("output" => output)) if isinteractive() exec_async() else exec() # for doctest end end ``` -------------------------------- ### QML.init_qquickview Source: https://juliagraphics.github.io/QML.jl/dev Initializes and returns a new QQuickView object. ```APIDOC ## QML.init_qquickview ### Description Creates and returns a new `QQuickView` object. ### Function Signature ```julia function init_qquickview() ``` ### Returns * `QQuickView` - A newly created QQuickView instance. ``` -------------------------------- ### Initialize QML Engine Source: https://juliagraphics.github.io/QML.jl/dev Create a QML engine using `init_qmlengine`. The engine's context can be modified via `root_context`, and it can be used to create `QQmlComponent`s. An engine for a `QQuickView` can also be obtained using the `engine` function. ```julia using QML init_qmlengine() ``` -------------------------------- ### Initialize QQuickView Source: https://juliagraphics.github.io/QML.jl/dev Create a `QQuickView` object using the `init_qquickview` function. This object is used to display QML user interfaces. ```julia using QML init_qquickview() ``` -------------------------------- ### QML.show Source: https://juliagraphics.github.io/QML.jl/dev Displays the QML view, equivalent to `QQuickView::show`. This makes the QML window visible to the user. ```APIDOC ## QML.show ### Description Equivalent to `QQuickView::show`. See example for `QQuickView`. ### Function Signature ``` function QML.show() ``` ``` -------------------------------- ### QML.create Source: https://juliagraphics.github.io/QML.jl/dev Creates a QML component, parenting it to the given QQmlContext. Equivalent to QQmlComponent::create. ```APIDOC ## QML.create ### Description Creates a QML component, equivalent to `QQmlComponent::create`. This function ensures the newly created object is parented to the provided `context`. See the example for `set_data` for usage. ### Function Signature ```julia function create(component::QQmlComponent, context::QQmlContext) ``` ### Parameters * `component` (QQmlComponent) - The QQmlComponent to create. * `context` (QQmlContext) - The QQmlContext to parent the created component to. ### Returns * The created QML object. ### Example (See example for `QML.set_data`) ``` -------------------------------- ### Load QML File with Properties Source: https://juliagraphics.github.io/QML.jl/dev Load a QML file into the current QML view using the `loadqml` function. Additional properties can be passed as keyword arguments. ```julia using QML loadqml(qmlfilename; properties...) ``` -------------------------------- ### Simulate Background Tasks with QTimer Source: https://juliagraphics.github.io/QML.jl/dev Illustrates using `QTimer` to simulate background tasks in Julia, connected to QML via `Connections`. ```julia using QML counter = Ref(0) increment() = counter[] += 1 @qmlfunction increment mktempdir() do folder path = joinpath(folder, "main.qml") write(path, """ import QtQuick import QtQuick.Controls import jlqml ApplicationWindow { visible: true Connections { target: timer function onTimeout() { Julia.increment() } } Button { text: "Start counting" onClicked: timer.start() } Timer { # unrelated, this is a timer to stop and continue testing running: true; repeat: false onTriggered: Qt.exit(0) } } """) loadqml(path, timer=QTimer()) exec() end ``` -------------------------------- ### QML.exec Source: https://juliagraphics.github.io/QML.jl/dev Executes the QML event loop, filling out a window. Use with QQmlApplicationEngine, QQuickView, or QQmlComponent. ```APIDOC ## QML.exec ### Description Fills out a window by executing the QML event loop. This function can be used with `QQmlApplicationEngine`, `QQuickView`, or `QQmlComponent`. Note that after calling `exec`, you may need to re-register functions (e.g., using `[@qmlfunction]`) if you intend to call `exec` again. ### Function Signature ```julia function exec() ``` ### Usage Call this function after setting up your QML components and engine/view. ``` -------------------------------- ### Clone QML.jl Repository Source: https://juliagraphics.github.io/QML.jl/dev/developer Clones the QML.jl repository from GitHub to your local machine. Replace USERNAME with your GitHub username. ```bash git clone https://github.com/USERNAME/QML.jl.git ``` -------------------------------- ### QML Application Window Structure Source: https://juliagraphics.github.io/QML.jl/dev This QML code defines a basic ApplicationWindow with a red background and a text element that displays properties from Julia. It imports necessary QML modules. ```qml import QtQuick import QtQuick.Controls import jlqml ApplicationWindow { id: mainWin title: "My Application" width: 100 height: 100 visible: true Rectangle { anchors.fill: parent color: "red" Text { anchors.centerIn: parent text: props.hi + Julia.world() } } } ``` -------------------------------- ### Base.string Source: https://juliagraphics.github.io/QML.jl/dev Converts a QByteArray to a Julia String. This is equivalent to the QByteArray::toString method. ```APIDOC ## Base.string ### Description Converts a `QByteArray` to a Julia `String`. This is equivalent to the `QByteArray::toString` method. ### Function Signature ```julia function string(data::QByteArray) ``` ### Parameters * `data` (QByteArray) - The byte array to convert. ### Returns * `String` - The converted string. ### Example ```julia using QML string(QByteArray("Hello, World!")) ``` ``` -------------------------------- ### QML.loadqml Source: https://juliagraphics.github.io/QML.jl/dev Loads a QML file and applies specified properties. This is a method of the QML module. ```APIDOC ## QML.loadqml ### Description Loads a QML file specified by `qmlfilename` and applies any additional keyword arguments as properties. ### Method Signature ```julia function loadqml(qmlfilename; properties...) ``` ### Parameters * `qmlfilename` (String) - The path to the QML file to load. * `properties...` - Arbitrary keyword arguments to set as properties on the loaded QML object. ### Usage This function is used to load and instantiate QML files within your Julia application. ``` -------------------------------- ### QML.qt_prefix_path Source: https://juliagraphics.github.io/QML.jl/dev Returns the Qt prefix path, equivalent to `QLibraryInfo::location(QLibraryInfo::PrefixPath)`. Useful for verifying the correct Qt version. ```APIDOC ## QML.qt_prefix_path ### Description Equivalent to `QLibraryInfo::location(QLibraryInfo::PrefixPath)`. Useful to check whether the intended Qt version is being used. ### Function Signature ``` function qt_prefix_path() ``` ### Example ```julia using QML isdir(qt_prefix_path()) ``` ``` -------------------------------- ### Activate Test Environment Source: https://juliagraphics.github.io/QML.jl/dev/developer Activates the test environment for the QML.jl project using the TestEnv package. ```julia using TestEnv; TestEnv.activate() ``` -------------------------------- ### QML.qmlcontext Source: https://juliagraphics.github.io/QML.jl/dev Creates an empty context for QML. This is required for the `create` function when initializing a QML application. ```APIDOC ## QML.qmlcontext ### Description Create an empty context for QML. Required for `create`. ### Function Signature ``` function qmlcontext() ``` ``` -------------------------------- ### Create and Use JuliaItemModel in QML ListView Source: https://juliagraphics.github.io/QML.jl/dev Illustrates the creation of a `JuliaItemModel` from a Julia array of structs to be used in QML views like `ListView`. It shows how to define a mutable struct with properties, construct the model, and interact with it from QML, including updating data and appending rows. ```julia using QML mutable struct Fruit name::String cost::Float64 end fruits = JuliaItemModel([Fruit("apple", 1.0), Fruit("orange", 2.0)]) ``` ```qml import QtQuick import QtQuick.Controls import QtQuick.Layouts ApplicationWindow { visible: true ListView { model: fruits anchors.fill: parent delegate: Row { Text { text: name } Button { text: "Sale" onClicked: cost = cost / 2 } Button { text: "Duplicate" onClicked: fruits.appendRow({"name": name, "cost": cost}) } Timer { running: true; repeat: false onTriggered: Qt.exit(0) } } } } } ``` -------------------------------- ### QML.set_source Source: https://juliagraphics.github.io/QML.jl/dev Sets the source file for a `QQuickView`. This function is used to load a QML file into a view, typically a window. ```APIDOC ## QML.set_source ### Description Equivalent to `QQuickView::setSource`. See the example for `init_qquickview`. The file path should be a path wrapped with `QUrl`. ### Function Signature ``` function set_source(window::QQuickView, file::QUrl) ``` ``` -------------------------------- ### Register Julia Functions for QML Source: https://juliagraphics.github.io/QML.jl/dev Shows how to register Julia functions for use in QML using the `@qmlfunction` macro. Functions are accessible via `Julia.function_name`. ```julia @qmlfunction function_names... ``` ```julia julia> using QML julia> greet() = "Hello, World!"; julia> @qmlfunction greet julia> mktempdir() do folder path = joinpath(folder, "main.qml") write(path, """ import jlqml import QtQuick import QtQuick.Controls ApplicationWindow { visible: true Text { text: Julia.greet() } Timer { running: true; repeat: false onTriggered: Qt.exit(0) } } """) loadqml(path) exec() end ``` -------------------------------- ### QUrl Type Source: https://juliagraphics.github.io/QML.jl/dev Used to pass filenames to `set_source`. An empty URL can be passed to `set_data`. ```julia struct QUrl([filename::String]) end ``` -------------------------------- ### Convert QByteArray to String Source: https://juliagraphics.github.io/QML.jl/dev Use the `string` function to convert a `QByteArray` back to a Julia string. This is equivalent to `QByteArray::toString`. ```julia using QML string(QByteArray("Hello, World!")) ``` -------------------------------- ### QML.setheadergetter! Source: https://juliagraphics.github.io/QML.jl/dev Sets a function to be called when retrieving header data for a `JuliaItemModel`. This customizes how header information is accessed. ```APIDOC ## QML.setheadergetter! ### Description Set `f` as function to call when getting header data. The signature of of should be: ``` f(data, row_or_col, orientation, role) ``` Here, `data` is the internal data array stored in the model, `row_or_col` is the index of the row or column, `orientation` is either `QML.Horizontal` for column headers or `QML.Vertical` for row headers and `role` is an integer describing the role (e.g. QML.DisplayRole) ### Method Signature ``` setheadergetter!(itemmodel::JuliaItemModel, f::Function) ``` ``` -------------------------------- ### QML.engine Source: https://juliagraphics.github.io/QML.jl/dev Retrieves the QML engine associated with a QQuickView. Equivalent to QQuickView::engine. ```APIDOC ## QML.engine ### Description Retrieves the QML engine associated with a `QQuickView`. This is equivalent to `QQuickView::engine`. To modify the context of a `QQuickView`, you can obtain the engine using this function and then get the root context using `root_context`. ### Function Signature ```julia function engine(quick_view::QQuickView) ``` ### Parameters * `quick_view` (QQuickView) - The QQuickView whose engine to retrieve. ### Returns * `QQmlEngine` - The QML engine of the QQuickView. ### Example ```julia using QML mktempdir() do folder path = joinpath(folder, "main.qml") write(path, """ import QtQuick import QtQuick.Controls Rectangle { Text { text: greeting } Timer { running: true; repeat: false onTriggered: parent.Window.window.close() } } """) quick_view = init_qquickview() context = root_context(engine(quick_view)) set_context_property(context, "greeting", "Hello, World!") set_source(quick_view, QUrlFromLocalFile(path)) QML.show(quick_view) exec() end ``` ``` -------------------------------- ### QML.setheadersetter! Source: https://juliagraphics.github.io/QML.jl/dev Sets a function to be called when setting header data for a `JuliaItemModel`. This allows custom logic for updating header information. ```APIDOC ## QML.setheadersetter! ### Description Set `f` as function to call when setting header data. The signature of of should be: ``` f(data, row_or_col, orientation, value, role) ``` Here, `value` is the value for the given header item. The other arguments are the same as in `setheadergetter!` ### Method Signature ``` setheadersetter!(itemmodel::JuliaItemModel, f::Function) ``` ``` -------------------------------- ### Emit Signal from Julia to QML Source: https://juliagraphics.github.io/QML.jl/dev Defines a Julia function that emits a signal, registers it with QML, and demonstrates its usage within a QML file. The QML file uses a JuliaSignals block to handle the emitted signal. ```julia using QML duplicate(value) = @emit duplicateSignal(value); @qmlfunction duplicate mktempdir() do folder path = joinpath(folder, "main.qml") write(path, """ import QtQuick import QtQuick.Controls import QtQuick.Layouts import jlqml ApplicationWindow { visible: true Column { TextField { id: input onTextChanged: Julia.duplicate(text) } Text { id: output } JuliaSignals { signal duplicateSignal(var value) """ ) end ``` -------------------------------- ### QByteArray Type Source: https://juliagraphics.github.io/QML.jl/dev Used to pass text to `set_data`. ```julia function QByteArray(a_string::String) end ``` -------------------------------- ### QML.content_item Source: https://juliagraphics.github.io/QML.jl/dev Retrieves the content item of a QQuickView, equivalent to QQuickWindow::contentItem. ```APIDOC ## QML.content_item ### Description Retrieves the content item of a `QQuickView`. This is equivalent to `QQuickWindow::contentItem`. ### Function Signature ```julia function content_item(quick_view::QQuickView) ``` ### Parameters * `quick_view` (QQuickView) - The QQuickView from which to get the content item. ### Returns * `QQuickItem` - The content item of the QQuickView. ### Example ```julia using QML using CxxWrap.CxxWrapCore: CxxPtr quick_view = mktempdir() do folder path = joinpath(folder, "main.qml") write(path, """ import QtQuick import QtQuick.Controls Rectangle { Timer { running: true; repeat: false onTriggered: Qt.exit(0) } } """) quick_view = init_qquickview() set_source(quick_view, QUrlFromLocalFile(path)) @assert content_item(quick_view) isa CxxPtr{QQuickItem} exec() end ``` ``` -------------------------------- ### Synchronize Julia Observable with QML Slider Source: https://juliagraphics.github.io/QML.jl/dev Shows how to use `JuliaPropertyMap` to store Julia values for QML access and enable two-way synchronization. Changes to an `Observable` in Julia update the QML element (e.g., a slider), and changes in QML update the `Observable`. ```julia using QML using Observables: Observable, on output = Observable(0.0) on(println, output) ``` ```qml import QtQuick import QtQuick.Controls import jlqml ApplicationWindow { visible: true Slider { ``` -------------------------------- ### QML.roles Source: https://juliagraphics.github.io/QML.jl/dev Retrieves all defined roles for a `JuliaItemModel`. This is used in conjunction with `addrole!` to manage model data roles. ```APIDOC ## QML.roles ### Description See all roles defined for a `JuliaItemModel`. See the example for `addrole!`. ### Method Signature ``` function roles(model::JuliaItemModel) ``` ``` -------------------------------- ### Execute QML Synchronously Source: https://juliagraphics.github.io/QML.jl/dev Use `exec` to display and interact with a QML window. This function blocks the main process until the QML window is closed. Note that functions may need to be reregistered with `@qmlfunction` if `exec` is called multiple times. ```julia using QML exec() ``` -------------------------------- ### Execute QML Asynchronously Source: https://juliagraphics.github.io/QML.jl/dev Use `exec_async` to run a QML interface without blocking the main process. This method keeps the REPL active by periodically polling the QML interface using a timer in the Julia event loop. ```julia using QML exec_async() ``` -------------------------------- ### QML.context_property Source: https://juliagraphics.github.io/QML.jl/dev Retrieves a context property from a QQmlContext. ```APIDOC ## QML.context_property ### Description Retrieves a context property from a `QQmlContext`. Refer to the example for `root_context` for usage. ### Function Signature ```julia function context_property(context::QQmlContext, item::AbstractString) ``` ### Parameters * `context` (QQmlContext) - The QQmlContext to retrieve the property from. * `item` (AbstractString) - The name of the context property. ### Returns * The value of the context property. ### Example (See example for `QML.root_context`) ``` -------------------------------- ### QML.addrole! Source: https://juliagraphics.github.io/QML.jl/dev Adds custom getter and setter functions to a JuliaItemModel for QML access. The setter is optional, making the role read-only if omitted. ```APIDOC ## QML.addrole! ### Description Adds custom `getter` (and optionally `setter`) functions to a `JuliaItemModel` for use by QML. If `setter` is not provided, the role becomes read-only. The `getter` processes an item before it is returned. The arguments for `setter` are `collection`, `new_value`, and `index`, similar to the standard `setindex!` function. Use `roles` to view defined roles. ### Function Signature ```julia function addrole!(model::JuliaItemModel, name::String, getter, [setter]) ``` ### Parameters * `model` (JuliaItemModel) - The model to add the role to. * `name` (String) - The name of the role to add. * `getter` - The function to retrieve the role's value. * `setter` (optional) - The function to set the role's value. ### Example ```julia using QML items = ["A", "B"] array_model = JuliaItemModel(items, false) addrole!(array_model, "item", identity, setindex!) roles(array_model)[256] "item" mktempdir() do folder path = joinpath(folder, "main.qml") write(path, """ import QtQuick import QtQuick.Controls import QtQuick.Layouts ApplicationWindow { visible: true ListView { model: array_model anchors.fill: parent delegate: TextField { placeholderText: item onTextChanged: item = text; } } Timer { running: true; repeat: false onTriggered: Qt.exit(0) } } """) loadqml(path; array_model = array_model) exec() end ``` ``` -------------------------------- ### QML.set_data Source: https://juliagraphics.github.io/QML.jl/dev Sets the QML code for a `QQmlComponent` from a Julia string. This allows dynamic creation and loading of QML components. ```APIDOC ## QML.set_data ### Description Equivalent to `QQmlComponent::setData`. Use this to set the QML code for a `QQmlComponent` from a Julia string literal wrapped in a `QByteArray`. Also requires an empty `QUrl`. See `QQmlComponent` for an example. ### Function Signature ``` function set_data(component::QQmlComponent, data::QByteArray, file::QUrl) ``` ``` -------------------------------- ### Add Custom Roles to JuliaItemModel Source: https://juliagraphics.github.io/QML.jl/dev Add custom getter and setter functions to a `JuliaItemModel` for use in QML. The setter is optional, making the role read-only if omitted. The getter processes an item before it's returned. ```julia using QML items = ["A", "B"] array_model = JuliaItemModel(items, false) addrole!(array_model, "item", identity, setindex!) roles(array_model)[256] ``` ```qml import QtQuick import QtQuick.Controls import QtQuick.Layouts ApplicationWindow { visible: true ListView { model: array_model anchors.fill: parent delegate: TextField { placeholderText: item onTextChanged: item = text; } } Timer { running: true; repeat: false onTriggered: Qt.exit(0) } } ``` ```julia mktempdir() do folder path = joinpath(folder, "main.qml") write(path, """ import QtQuick import QtQuick.Controls import QtQuick.Layouts ApplicationWindow { visible: true ListView { model: array_model anchors.fill: parent delegate: TextField { placeholderText: item onTextChanged: item = text; } } Timer { running: true; repeat: false onTriggered: Qt.exit(0) } } """) loadqml(path; array_model = array_model) exec() end ``` -------------------------------- ### QML.@emit Source: https://juliagraphics.github.io/QML.jl/dev Emits a signal from Julia to QML, allowing Julia code to trigger events or send data to QML components. QML handles these signals using a `JuliaSignals` block. ```APIDOC ## QML.@emit ### Description Emit a signal from Julia to QML. Handle signals in QML using a `JuliaSignals` block. See the example below for syntax. Warning There must never be more than one JuliaSignals block in QML ### Macro Signature ``` @emit signal_name(arguments...) ``` ### Example ```julia using QML duplicate(value) = @emit duplicateSignal(value) @qmlfunction duplicate mktempdir() do folder path = joinpath(folder, "main.qml") write(path, """ import QtQuick import QtQuick.Controls import QtQuick.Layouts import jlqml ApplicationWindow { visible: true Column { TextField { id: input onTextChanged: Julia.duplicate(text) } Text { id: output } JuliaSignals { signal duplicateSignal(var value) """ ) end ``` ``` -------------------------------- ### QML.qmlfunction Source: https://juliagraphics.github.io/QML.jl/dev Registers a Julia function with a specified name for use in QML. This allows QML to call Julia functions directly. ```APIDOC ## QML.qmlfunction ### Description Register `a_function` using `function_name`. If you want to register a function under its own name, you can use `@qmlfunction`. Note, however, that you can't use the macro for registering functions from a non-exported module or registering functions with `!` in the name. ### Function Signature ``` function qmlfunction(function_name::String, a_function) ``` ``` -------------------------------- ### QML.set_context_property Source: https://juliagraphics.github.io/QML.jl/dev Sets a property on a given QML context. This function is crucial for passing data from Julia to the QML environment. ```APIDOC ## QML.set_context_property ### Description Set properties. See `root_context` for an example. ### Function Signature ``` set_context_property(context::QQmlContext, name::String, value::Any) ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.