PDA

View Full Version : Cannot assign to non-existent default property



jeff28
3rd September 2012, 09:27
Hi, guys I am trying to add qml types. Here is my example.qml:




import InsideDial 1.0

import QtQuick 1.1

InsideDial {

value: 12

Image{
x: -19; y: -201
source: "svg/Background(Fblack).svg"
}
Image{
id: needle
x: 184; y: -80
smooth: true
source: "svg/Needle(w).svg"
transform: Rotation {
id: needleRotation
origin.x: 6; origin.y: 100
angle: calculateAngle(value)
}
}
function calculateAngle(value){
var angle = 0;
if(value >= 0)
angle = Math.min(Math.max(0, root.value*2.6 - 100), 90);
else
angle = Math.min(Math.max(-90, root.value*2.6 + 100), 0);
return angle;
}

}


And here is my main.cpp:



#include <QCoreApplication>
#include <QDeclarativeEngine>
#include <QDeclarativeComponent>
#include <QDebug>
#include "InsideDial.h"

int main(int argc, char ** argv)
{
QCoreApplication app(argc, argv);
qmlRegisterType<InsideDial>("InsideDial", 1,0, "InsideDial");

QDeclarativeEngine engine;
QDeclarativeComponent component(&engine, QUrl("qrc:example.qml"));
InsideDial *dial = qobject_cast<InsideDial *>(component.create());
if (dial) {

qWarning() << "The dial " << dial->value() << " valued";
} else {
qWarning() << component.errors();
}
qDebug() << component.errors();
return 0;

}



When I run my project I get this error :

QDeclarativeComponent: Component is not ready
(qrc:example.qml:9:5: Cannot assign to non-existent default property)
All of my .svg files are added to my .qrc file but I don't know how to fix this. Could you please help me?

Added after 1 20 minutes:

I have also tried this in my main.cpp:



#include <QCoreApplication>
#include <QDeclarativeEngine>
#include <QDeclarativeComponent>
#include <QDebug>
#include "InsideDial.h"

int main(int argc, char ** argv)
{
QCoreApplication app(argc, argv);
qmlRegisterType<InsideDial>("InsideDial", 1,0, "InsideDial");

QDeclarativeEngine engine;
QDeclarativeComponent component(&engine, QUrl("qrc:example.qml"));
QObject *o;
while(!component.isReady())
o = component.create();
InsideDial *dial = qobject_cast<InsideDial *>(o);
if (dial) {

qWarning() << "The dial " << dial->value() << " valued";
} else {
qWarning() << component.errors();
}
qDebug() << component.errors();
return 0;

}


But this does not work too..

wysota
8th September 2012, 05:56
What does your InsideDial class look like?