Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to write an app for Ubuntu Touch based on the QtQuick2ApplicationViewer template and the app needs to write to a file (e.g. '/tmp/test.log').

I tested with using a function/macro Q_INVOKABLE:

Q_INVOKABLE void QtQuick2ApplicationViewer::setData3(void) {

    qDebug() << "setData";


...and share it by Q_INVOKABLE.

But I can not call the function in my .qml, and I got an error:

...main.qml:289: ReferenceError: setData3 "is not defined"

Has anyone got a working file to download?

Or a working method to create a file using a cpp-function+qml as .pro to download?

Working in the qtcreator-version for ubuntutouch?

share|improve this question
up vote 4 down vote accepted

I found the solution myself and I want to explain what I did wrong.

I forgot in:


    #include <QQmlEngine>
    #include <QQmlComponent>
    #include "stringhelper.h"
    qmlRegisterType<StringHelper>("MyStringHelper", 1, 0, "StringHelper");


    .....public slots:...
           Q_INVOKABLE void stringxx(void){
              qDebug() << "  stringhelper.h:stringxx GOT YOU !! :-) ";

now in main.qml :

    import MyStringHelper 1.0

    StringHelper {
            id: my_StringH


now I am able to call my stringxx-function and more powerfull functions im .qml

regards Sascha

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.