5

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?

sUbuPack
  • 182

1 Answers1

4

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

sUbuPack
  • 182