Namespaces
Variants
Actions

Non-GUI-Qt-Quick-applications

Jump to: navigation, search
Article Metadata

Article
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 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.

This page was last modified on 11 October 2012, at 04:17.
115 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved