2012-03-08 5 views
0

こんにちは、QMLファイルのテキストエリアのテキストをC++で変更する

QTで何かを計算して指定したテキストエリアに出力するアプリケーションを作成しようとしています。

私はどのように私はユーザーがmouseareaを押すと、テキストを変更することができます達成することができます。私はすでに次のコードを持っている:

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

答えて

1
MouseArea { 
[...] 
    onClicked: { 
     tekst_gebied.text = "some text" 
    } 
} 
+0

真の、しかし、私は必要いくつかの数学を行うには、その変更の出力とテキストエリア – Mathlight

+0

だから? OnClickedで何をしていても、 "tekst_gebied.text"に結果を代入してください。 – Koying

+0

あなたが言うところなら... – Mathlight

関連する問題