![](/img/trans.png)
[英]How do I change the label text in one qml file from another qml file using Qt/QML/C++ in Cascades, Blackberry 10?
[英]change text of textarea in qml file with c++
你好
我正在尝试在QT中创建一个应用程序,该应用程序可以计算内容并将其输出到指定的文本区域。
我如何实现这一点,即当用户按下鼠标区域时可以更改文本。 我已经有以下代码:
main.cpp
#include <QtGui/QApplication>
#include <QtDeclarative>
#include <QGraphicsObject>
#include "qmlapplicationviewer.h"
#include "eigen_function_header.h"
Q_DECL_EXPORT int main(int argc, char *argv[])
{
QScopedPointer<QApplication> app(createApplication(argc, argv));
qmlRegisterType<MyObject>("com.myself", 1, 0, "MyObject");
QmlApplicationViewer viewer;
viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
viewer.setMainQmlFile(QLatin1String("qml/tw_looptijden_berekenen/main.qml"));
viewer.showExpanded();
return app->exec();
}
eigen_function_header.h
#ifndef EIGEN_FUNCTION_HEADER_H
#define EIGEN_FUNCTION_HEADER_H
#include <QObject>
class MyObject : public QObject{
Q_OBJECT
public:
explicit MyObject (QObject* parent = 0) : QObject(parent) {}
Q_INVOKABLE int reken_tijden_uit(){
// tekst_gebied
return 1;
}
};
#endif // EIGEN_FUNCTION_HEADER_H
main.qml
import QtQuick 1.1
import com.myself 1.0
Rectangle {
width: 360
height: 360
Text {
id: tekst_gebied
text: qsTr("Hello World")
anchors.centerIn: parent
}
MyObject {
id: myobject
}
MouseArea {
x: 0
y: 0
width: 360
height: 251
anchors.rightMargin: 0
anchors.bottomMargin: 109
anchors.leftMargin: 0
anchors.topMargin: 0
z: 1
anchors.fill: parent
onClicked: {
console.log(myobject.reken_tijden_uit());
}
}
Text {
id: text1
x: 96
y: 305
text: qsTr("text")
font.pixelSize: 12
}
}
MouseArea {
[...]
onClicked: {
tekst_gebied.text = "some text"
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.