Skip to content

Instantly share code, notes, and snippets.

@lbt
Last active August 29, 2015 14:05
Show Gist options
  • Save lbt/8ec24d664ff3cf3b08d3 to your computer and use it in GitHub Desktop.
Save lbt/8ec24d664ff3cf3b08d3 to your computer and use it in GitHub Desktop.
class SparkCloud : public QObject
{
Q_OBJECT
public:
explicit SparkCloud(QUrl apiurl, QObject *parent = 0);
explicit SparkCloud(QObject *parent = 0);
Q_INVOKABLE QList<QObject*> devices() { return (QList<QObject*>)(m_devices.values()); }
Q_INVOKABLE QList<QString> device_ids() { return m_devices.keys(); }
Q_INVOKABLE SparkDevice* device(QString id) { return m_devices[id]; }
...
}
class SparkDevice : public QObject
{
Q_OBJECT
public:
explicit SparkDevice(SparkCloud *cloud, QString id,
QString name, bool connected, QObject *parent = 0);
explicit SparkDevice(QObject *parent = 0);
Q_INVOKABLE QString id() { return m_id; }
Q_INVOKABLE QString name() { return m_name; }
...
}
Page {
id: page
SilicaListView {
id: listView
model: SparkCloud.devices()
anchors.fill: parent
header: PageHeader {
title: "Nested Page"
}
delegate: BackgroundItem {
id: delegate
Label {
x: Theme.paddingLarge
text: "Item " + index + " " + model.modelData.name()
anchors.verticalCenter: parent.verticalCenter
color: delegate.highlighted ? Theme.highlightColor : Theme.primaryColor
}
onClicked: console.log("Clicked " + index)
}
VerticalScrollDecorator {}
}
}
main()
{
...
view->rootContext()->setContextProperty("SparkCloud", &s);
// We could support multiple clouds:
qmlRegisterType<SparkCloud>("harbour.sparky.SparkCloud", 1, 0, "SparkCloud");
qmlRegisterType<SparkDevice>("harbour.sparky.SparkCloud", 1, 0, "SparkDevice");
qmlRegisterType<SparkFunction>("harbour.sparky.SparkCloud", 1, 0, "SparkFunction");
qmlRegisterType<SparkVariable>("harbour.sparky.SparkCloud", 1, 0, "SparkVariable");
@rburchell
Copy link

Q_INVOKABLE QList<QObject*> devices() { return (QList<QObject*>)(m_devices.values()); }

try

Q_INVOKABLE QList<QObject*> devices() { return static_cast<QList<QObject*> >(m_devices.values()); }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment