I'm stuck with a "design/implemantation" problem in Qt. At the moment I'm not even sure if thats a smart design... That's my first post here and I don't really know where to start...
So I'll try is this way... At the moment I have something like this:
class NewProperty : public QObject
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName)
.
.
.
public:
NewProperty(const QString &name, QObject *parent = 0);
QString name()const;
void setName(const QString &name);
.
.
.
private:
QString m_s_name;
};
That's a "NewProperty" Class I want to have in "MyClass" cause in the end there will be much more than just a "name" Property ... The NewProject.cpp file is pretty basic at the moment...
And there will be also several MyClasses in the project.
My "MyClass" will have several "NewProperty" 's elements in the end... But I'm not sure how to pass the "NewProperty" to QML in the/a right/nice way. I tried to do something like this:
class QML_EMail : public Base_Output
{
Q_OBJECT
public:
NewProperty prop1;
NewProperty prop2;
.
.
.
};
main.cpp
...
qmlRegisterType<NewProperty> ("NewProperty", 1, 0, "NewProperty");
QML_EMail email
ctx->setContextProperty("email", QVariant::fromValue(&email));
...
If I try to call something like this in the QML file:
import NewProperty 1.0
Rectangle {
id: emailStart
Component.onCompleted:
{
console.log(email.prop1.name)
}
I only get this Message: TypeError: Cannot read property 'name' of undefined
I would appreciate any help or hints for better coding...
regards,
Moe