Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.


From Wiki
Jump to: navigation, search
Article Metadata
Created: achipa (05 Jan 2011)
Last edited: hamishwillee (11 Oct 2012)

It is possible to write a non-GUI QtQuick application. The use cases for that are if you want to create a console based application (a la ), or simply if you wish to construct non-visual QObjects in a structured way (think about it as CSV on steroids). Here's an example for your main.cpp

#include <QtCore/QCoreApplication>
#include <QtDeclarative/QDeclarativeEngine>
#include <QtDeclarative/QDeclarativeContext>
#include <QtDeclarative/QDeclarativeComponent>
int main(int argc, char *argv[])
QCoreApplication app(argc, argv);
QDeclarativeEngine engine;
QDeclarativeContext *context = new QDeclarativeContext(engine.rootContext());
QDeclarativeComponent component(&engine, QLatin1String("main.qml"));
QObject *window = component.create(context);
return app.exec();

and then a main.qml that would look like

import Qt 4.7
QtObject {
Component.onCompleted: console.log("Hello world");

You cannot render the standard graphical elements (Rectangle, Text, etc), so in the case of a curses UI you would have to implement your own textual widgets, but non-visual elements (like Timers) are usable as-is:

import Qt 4.7
Item {
Timer {
interval: 500; running: true; repeat: true;
onTriggered: console.log("tick");

Note that some Elements in QtQuick actually depend on some aspects of the GUI which might not be apparent. In the example above, we needed to switch QtObject with Item because Timer wants to synchronize with animations, something not provided by QtObject, only visual items like Item.

Wrapping text-mode widget libraries like CDK or urwid are left as an exercise to the reader.

This page was last modified on 11 October 2012, at 01:17.
52 page views in the last 30 days.