Qt · C++ · AI
Previewable AI actions for Qt applications
Use Qt's meta-object system to turn natural-language requests into explicit, reviewable operations over selected application objects.
By Qmob engineering team · December 4, 2026 · 5 min read

A language model can suggest that an application “move the selected shape to the right.” The difficult part is deciding which live object that means, whether its position can be changed, and what should happen if the model gets either answer wrong. Passing arbitrary model output straight to application code leaves those decisions implicit.
Qt already has a useful boundary for this problem: the meta-object system. An application can expose selected QObject instances, properties, and invokable methods, then ask a model for a plan expressed only in terms of that surface. A person or application policy can inspect the plan before anything changes.
Start with an intentional object surface
The application registers only objects relevant to prompting. Qt metadata describes their readable and writable properties, invokable methods, and relationships. A registry assigns stable references so a plan can address an object without asking the model to guess a pointer or search arbitrary UI internals.
This abbreviated class focuses on the relevant declarations:
class Shape : public QObject {
Q_OBJECT
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
Q_PROPERTY(qreal x READ x WRITE setX NOTIFY xChanged)
Q_PROPERTY(qreal y READ y WRITE setY NOTIFY yChanged)
public:
Q_INVOKABLE explicit Shape(QObject *parent = nullptr);
Q_INVOKABLE void moveTo(qreal x, qreal y);
// Accessors and signals omitted.
};
The declarations are a vocabulary, not blanket permission. A registry must still decide which instances are visible, which members can be used, and whether creation or deletion is allowed. An exposed Q_PROPERTY might be readable for context yet unwritable by an AI action.

Give the model a bounded map
The planner builds a compact context from registered instances and discovered types. It can follow QObject properties and supported collections to describe relevant child objects, while leaving unrelated implementation details out. Class metadata tells the model which property and method names exist; live instance data tells it what objects can be targeted.
This context needs limits. Traversing every reachable object can make prompts large, slow, and ambiguous. For a substantial application, select roots, cap traversal depth and collection size, and include runtime values only where they help resolve the user's request. Those limits also reduce how much application state reaches an external model provider.
Plan first, apply second
An operation-oriented response is easier to review than free-form code. For example, a request to recolor a registered shape might yield:
{
"summary": "Change the selected shape to green",
"confidence": 0.93,
"issues": [],
"mode": "operations",
"operations": [{
"op": "setProperty",
"target": { "type": "object", "ref": "selected-shape" },
"property": "color",
"value": "#2FB666"
}],
"script": ""
}
The executor should resolve selected-shape against the current registry, check that color is permitted and writable, convert the value to QColor, and report failure if any step fails. Creation, deletion, method calls, and collection selections need equally explicit rules. Model confidence is useful context, but it does not replace validation or approval.
A preview should show the actual operations that will run. In multi-step requests, ordering matters: creating an object must precede changes to it. If the model describes five edits but emits only four operations, the preview exposes that gap before mutation.
The same contract works across Qt UIs
The example application demonstrates shape editing in both Qt Quick and Qt Widgets. The QML example wires a registry, provider, planner, and applier declaratively; the Widgets example connects the same stages in C++. Both ultimately operate on QObject properties and invokable methods, so the UI technology does not define the action contract.

See the runtime in action
These short recordings show the Qt Widgets example turning prompts into reviewable plans and changes.
In this small example, a local qwen3-coder:30b model and a hosted GPT-5.4 model handled several requests. Compound spatial instructions also exposed errors and showed why domain rules matter: a model cannot infer whether a shape's x and y denote its center or top-left corner from property names alone. These are qualitative observations from a small demo, not evidence of reliability across applications.
Keep the escape hatch narrow
Some requests do not fit a fixed operation vocabulary. A JavaScript fallback through QJSEngine can express them, but a script has a larger execution surface and is harder to preview, validate, and reverse. Prefer structured operations; make script access an explicit policy decision with tightly scoped object wrappers.
The remaining engineering work is substantial: permissions for each object and operation, stale-reference handling when the object graph changes, transaction or undo support for partial failures, bounded context generation, and tests against deeper real-world graphs. A previewable plan makes these concerns visible; it does not solve them automatically.
The broader idea is useful beyond a shapes demo. Qt's existing reflection can supply a well-defined interface between natural-language intent and application behavior, provided the application—not the model—remains responsible for exposure, validation, and execution.
Further reading: Qt meta-object system, Qt properties, QJSEngine. Building a Qt application that needs a carefully controlled AI interface? Talk with Qmob.