sUb*_*ack 5 application-development qml qt5 ubuntu-touch
我想基于 QtQuick2ApplicationViewer 模板为 Ubuntu Touch 编写一个应用程序,并且该应用程序需要写入一个文件(例如“/tmp/test.log”)。
我使用函数/宏进行了测试Q_INVOKABLE
:
Q_INVOKABLE void QtQuick2ApplicationViewer::setData3(void) {
qDebug() << "setData";
}
Run Code Online (Sandbox Code Playgroud)
...并分享给Q_INVOKABLE
.
但是我无法在我的 .qml 中调用该函数,并且出现错误:
...main.qml:289: ReferenceError: setData3 "is not defined"
Run Code Online (Sandbox Code Playgroud)
有没有人要下载一个有效的 demo.pro 文件?
或者使用 cpp-function+qml 作为 .pro 创建文件的工作方法进行下载?
在 ubuntutouch 的 qtcreator 版本中工作?
我自己找到了解决方案,我想解释一下我做错了什么。
我忘了在:
#include <QQmlEngine>
#include <QQmlComponent>
#include "stringhelper.h"
to
qmlRegisterType<StringHelper>("MyStringHelper", 1, 0, "StringHelper");
Run Code Online (Sandbox Code Playgroud)
...class...
.....public slots:...
Q_INVOKABLE void stringxx(void){
qDebug() << " stringhelper.h:stringxx GOT YOU !! :-) ";
}
Run Code Online (Sandbox Code Playgroud)
import MyStringHelper 1.0
StringHelper {
id: my_StringH
}
my_StringH.stringxx();
Run Code Online (Sandbox Code Playgroud)
现在我可以在 .qml 中调用我的 stringxx 函数和更强大的函数
问候萨沙
归档时间: |
|
查看次数: |
1065 次 |
最近记录: |