making it work
This commit is contained in:
@@ -1,13 +1,14 @@
|
|||||||
import QtQuick
|
import QtQuick
|
||||||
import QtQuick.Controls
|
import QtQuick.Controls
|
||||||
|
|
||||||
Rectangle {
|
Window {
|
||||||
id: window
|
id: window
|
||||||
width: 640
|
width: 640
|
||||||
height: 480
|
height: 480
|
||||||
visible: true
|
visible: true
|
||||||
|
title: "WIFI Picker"
|
||||||
|
|
||||||
required property var networksModel
|
property var model
|
||||||
|
|
||||||
signal scanNetworks()
|
signal scanNetworks()
|
||||||
|
|
||||||
@@ -19,9 +20,17 @@ Rectangle {
|
|||||||
|
|
||||||
ListView {
|
ListView {
|
||||||
id: listview
|
id: listview
|
||||||
objectName: "listview"
|
model: window.model
|
||||||
model: parent.networksModel
|
width: 100
|
||||||
delegate: Rectangle {
|
height: 200
|
||||||
|
// model: ListModel {
|
||||||
|
// ListElement { name: "Item 1"; value: 10 }
|
||||||
|
// ListElement { name: "Item 2"; value: 20 }
|
||||||
|
// ListElement { name: "Item 3"; value: 30 }
|
||||||
|
// }
|
||||||
|
|
||||||
|
delegate: Item {
|
||||||
|
height: 20
|
||||||
required property string name
|
required property string name
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
|
|||||||
+10
-1
@@ -18,7 +18,9 @@ NetworksModel::NetworksModel(QObject *parent)
|
|||||||
:
|
:
|
||||||
QAbstractListModel(parent)
|
QAbstractListModel(parent)
|
||||||
{
|
{
|
||||||
|
QList<Network> networks;
|
||||||
|
networks.append(Network("Gita test"));
|
||||||
|
this->m_networks = networks;
|
||||||
}
|
}
|
||||||
|
|
||||||
int NetworksModel::rowCount(const QModelIndex &parent) const
|
int NetworksModel::rowCount(const QModelIndex &parent) const
|
||||||
@@ -53,6 +55,13 @@ void NetworksModel::scan()
|
|||||||
this->m_networks = networks;
|
this->m_networks = networks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QHash<int, QByteArray> NetworksModel::roleNames() const
|
||||||
|
{
|
||||||
|
QHash<int, QByteArray> roles;
|
||||||
|
roles[NetworksModel::NetworkRoles::NameRole] = "name";
|
||||||
|
return roles;
|
||||||
|
}
|
||||||
|
|
||||||
Network::Network(const QString &name)
|
Network::Network(const QString &name)
|
||||||
: m_name(name)
|
: m_name(name)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -39,6 +39,9 @@ public:
|
|||||||
public slots:
|
public slots:
|
||||||
void scan();
|
void scan();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QHash<int, QByteArray> roleNames() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<Network> m_networks;
|
QList<Network> m_networks;
|
||||||
NetworkScanner m_networkScanner;
|
NetworkScanner m_networkScanner;
|
||||||
|
|||||||
@@ -10,20 +10,29 @@ int main(int argc, char *argv[])
|
|||||||
QGuiApplication app(argc, argv);
|
QGuiApplication app(argc, argv);
|
||||||
|
|
||||||
NetworksModel model;
|
NetworksModel model;
|
||||||
|
qDebug() << "now has " << model.rowCount() << Qt::endl;
|
||||||
|
|
||||||
QQuickView view;
|
QQmlApplicationEngine engine;
|
||||||
view.setResizeMode(QQuickView::SizeRootObjectToView);
|
const QUrl url(u"qrc:/wifipicker/Main.qml"_qs);
|
||||||
view.setInitialProperties({{"networksModel", QVariant::fromValue(&model)}});
|
QObject::connect(
|
||||||
view.setSource(QUrl("qrc:/wifipicker/Main.qml"));
|
&engine,
|
||||||
view.show();
|
&QQmlApplicationEngine::objectCreationFailed,
|
||||||
|
&app,
|
||||||
|
[]() { QCoreApplication::exit(-1); },
|
||||||
|
Qt::QueuedConnection);
|
||||||
|
engine.load(url);
|
||||||
|
|
||||||
if (!view.rootObject())
|
|
||||||
|
QObject *rootObject = engine.rootObjects().first();
|
||||||
|
if (!rootObject)
|
||||||
{
|
{
|
||||||
qDebug() << "No root object found" << Qt::endl;
|
qDebug() << "Problem in finding root object" << Qt::endl;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
QObject *rootObject = view.rootObject();
|
engine.setInitialProperties({{"model", QVariant::fromValue(&model)}});
|
||||||
|
rootObject->setProperty("model", QVariant::fromValue(&model));
|
||||||
|
|
||||||
QObject::connect(rootObject, SIGNAL(scanNetworks()), &model, SLOT(scan()));
|
QObject::connect(rootObject, SIGNAL(scanNetworks()), &model, SLOT(scan()));
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user