Non-GUI-Qt-Quick-applications
Article Metadata
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 http://upload.wikimedia.org/wikipedia/commons/c/c5/Fdedit.png ), 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.

