showing items after 10 or so items in the model data

This commit is contained in:
talksik
2024-02-08 14:40:23 -08:00
parent f347a5d936
commit 705dc359b0
3 changed files with 30 additions and 31 deletions
+20 -22
View File
@@ -1,5 +1,6 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
Window {
id: window
@@ -8,34 +9,31 @@ Window {
visible: true
title: "WIFI Picker"
property var model
signal scanNetworks()
Button {
id: scanbutton
text: "Scan for networks"
onClicked: window.scanNetworks()
}
Button {
id: scanbutton
text: "Scan for networks"
onClicked: window.scanNetworks()
}
ListView {
id: listview
model: window.model
width: 100
height: 200
// model: ListModel {
// ListElement { name: "Item 1"; value: 10 }
// ListElement { name: "Item 2"; value: 20 }
// ListElement { name: "Item 3"; value: 30 }
// }
ListView {
id: listview
model: networksModel
anchors.fill: parent
// 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
delegate: Item {
height: 20
required property string name
Text {
Text {
text: parent.name
}
}
}
}
}
+7 -4
View File
@@ -18,9 +18,6 @@ NetworksModel::NetworksModel(QObject *parent)
:
QAbstractListModel(parent)
{
QList<Network> networks;
networks.append(Network("Gita test"));
this->m_networks = networks;
}
int NetworksModel::rowCount(const QModelIndex &parent) const
@@ -47,12 +44,18 @@ QVariant NetworksModel::data(const QModelIndex &index, int role) const
void NetworksModel::scan()
{
beginInsertRows(QModelIndex(), this->rowCount(), this->rowCount());
QList<Network> networks = this->m_networkScanner.scanForNetworks();
for (const Network& network: networks)
{
qDebug() << "Got network: " << network.name() << Qt::endl;
this->m_networks << network;
}
this->m_networks = networks;
qDebug() << "now have " << this->m_networks.size() << Qt::endl;
endInsertRows();
}
QHash<int, QByteArray> NetworksModel::roleNames() const
+3 -5
View File
@@ -4,12 +4,14 @@
#include <QtQuick/qquickitem.h>
#include <QtQuick/qquickview.h>
#include <NetworkScanner.h>
#include <QQmlContext>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
NetworksModel model;
model.scan();
qDebug() << "now has " << model.rowCount() << Qt::endl;
QQmlApplicationEngine engine;
@@ -20,9 +22,9 @@ int main(int argc, char *argv[])
&app,
[]() { QCoreApplication::exit(-1); },
Qt::QueuedConnection);
engine.rootContext()->setContextProperty("networksModel", &model);
engine.load(url);
QObject *rootObject = engine.rootObjects().first();
if (!rootObject)
{
@@ -30,11 +32,7 @@ int main(int argc, char *argv[])
return -1;
}
engine.setInitialProperties({{"model", QVariant::fromValue(&model)}});
rootObject->setProperty("model", QVariant::fromValue(&model));
QObject::connect(rootObject, SIGNAL(scanNetworks()), &model, SLOT(scan()));
return app.exec();
}