Qt throws the following error at runtime.
Unable to assign LIMITS_T to LIMITS_T
I assume that Qt needs more meta data information, but I don't know what I missing. I have done everything to declare the metatype:
limits.h
class LIMITS_T : public QObject{
Q_OBJECT
Q_PROPERTY(float min READ readMin WRITE writeMin NOTIFY minChanged)
public:
LIMITS_T() : QObject() {}
LIMITS_T(const LIMITS_T& limit) : QObject()
{
this->min = limit.min;
}
float min = 0;
float readMin() { return min; }
void writeMin(float min) { this->min = min; }
bool operator = (const LIMITS_T &limit)
{
this->min = limit.min;
}
signals:
void minChanged();
};
Q_DECLARE_METATYPE(LIMITS_T)
This is a simplified version of the splitBarGauge class
splitDialGauge.h
class SplitDialGauge : public QQuickPaintedItem
{
Q_OBJECT
Q_PROPERTY(LIMITS_T limits READ getLimits WRITE setLimits NOTIFY limitsChanged)
public:
SplitDialGauge(QQuickItem *parent = 0);
protected:
LIMITS_T limits;
virtual LIMITS_T getLimits();
virtual void setLimits(LIMITS_T value);
}
splitDialGauge.cpp
#include "splitBarGauge.h"
SplitDialGauge::SplitDialGauge(QQuickItem *parent = 0);
: QQuickPaintedItem(parent)
{
}
LIMITS_T SplitDialGauge::getLimits()
{
return this->limits;
}
void SplitDialGauge::setLimits(LIMITS_T limits)
{
this->limits = limits;
update();
}
And I register the class with the Qt Metadata system
#include "limits.h"
#include "splitDialGauge.h"
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
qmlRegisterType<SplitDialGauge>("ExampleModule", 1, 0, "SplitDialGauge");
qmlRegisterType<LIMITS_T>("ExampleModule", 1, 0, "Limits");
qRegisterMetaType<LIMITS_T>();
QQmlApplicationEngine engine;
engine.load(QUrl(QLatin1String("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
return app.exec();
}
Here is a snipet from the QML file
import ExampleModule 1.0
ApplicationWindow {
visible: true
width: 800
height: 480
SplitDialGauge {
Limits {
id: qtyLimits
min: 4
}
height: 200
width: 50
limits: qtyLimits
}
}