Привет,
Я пытаюсь создать приложение в 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
}
}