C++ 使用c+;更改qml文件中textarea的文本+;
嗨 我正在尝试在QT中创建一个应用程序,它可以计算某些内容并在指定的文本区域中输出这些内容 我如何才能做到这一点,当用户按下鼠标earea时,我可以更改文本。我已经得到了以下代码: main.cppC++ 使用c+;更改qml文件中textarea的文本+;,c++,qt,text,qml,C++,Qt,Text,Qml,嗨 我正在尝试在QT中创建一个应用程序,它可以计算某些内容并在指定的文本区域中输出这些内容 我如何才能做到这一点,当用户按下鼠标earea时,我可以更改文本。我已经得到了以下代码: main.cpp #include <QtGui/QApplication> #include <QtDeclarative> #include <QGraphicsObject> #include "qmlapplicationviewer.h" #include "eigen
#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();
}
是的,但是我需要做一些数学运算,然后用它的输出改变文本区域,所以呢?在点击时做任何你必须做的,然后把结果分配给“TekStGeBiEd.text”,如果你想从QML调用C++函数来做这个链接的数学或其他处理,将会有帮助。
#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
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"
}
}