Hi guys
I want to use Qt Quick/C++ together. For this, I wrote SteelProfile Class (C++) and own functions. I can’t assign “steelprofileID.steelStandardName” value to ListElement. There is a weird situation. This code(on below) shows to me correct value, but I can’t assign to ListElement. I got ListElement: cannot use script for property value error.
console.log("Value: " + steelprofileID.steelStandardName)
There is the problem?
steelprofile.h
class SteelProfile : public QObject
{
Q_OBJECT
Q_PROPERTY(QString steelStandardName READ steelStandardName WRITE setSteelStandardName) //NOTIFY steelStandardNameChanged
public:
explicit SteelProfile(QObject *parent = 0);
signals:
public slots:
Q_INVOKABLE QString steelStandardName() const;
void setSteelStandardName(const QString &steelStandardName);
private:
QString sName;
};
steelprofile.cpp
SteelProfile::SteelProfile(QObject *parent) :
QObject(parent)
{
qDebug() << "SteelProfile()";
sName = "Europe";
}
QString SteelProfile::steelStandardName() const{
qDebug() << "steelStandardName()";
return sName;
}
void SteelProfile::setSteelStandardName(const QString &steelStandardName){
qDebug() << "setSteelStandardName()";
sName = steelStandardName;
}
qml file
import QtQuick 2.1
import QtQuick.Controls 1.1
import QtQuick.Controls.Styles 1.1
import SteelProfile 1.0
Item {
width: parent.width
height: parent.height
SteelProfile{
id: steelprofileID
steelStandardName: "Europe"
}
ListModel{
id:steelStandardModel
ListElement{
//steelStandardName: "Europe"
steelStandardName: steelprofileID.steelStandardName //Gets error here
...
}
ListElement{
steelStandardName: "US"
...
}
}
...
main.cpp
#include <QtGui/QGuiApplication>
#include "qtquick2applicationviewer.h"
#include "steelprofile.h"
#include <QQmlApplicationEngine>
#include <QQuickWindow>
#include <QQmlComponent>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
qmlRegisterType<SteelProfile>("SteelProfile", 1,0, "SteelProfile");
SteelProfile *sProfile = new SteelProfile;
QQmlApplicationEngine engine;
engine.load(QUrl("qml/StackView1/main.qml"));
QObject *topLevel = engine.rootObjects().value(0);
QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);
window->show();
return app.exec();
}
↧








