Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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 demo.pro 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

1 Answer 1

up vote 4 down vote accepted

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

I forgot in:

main.c

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

stringhelper.h:

    ...class...
    .....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
    }

    my_StringH.stringxx();

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

regards Sascha

share|improve this answer

Your Answer

 
discard

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.