showing items after 10 or so items in the model data
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import QtQuick
|
import QtQuick
|
||||||
import QtQuick.Controls
|
import QtQuick.Controls
|
||||||
|
import QtQuick.Layouts
|
||||||
|
|
||||||
Window {
|
Window {
|
||||||
id: window
|
id: window
|
||||||
@@ -8,34 +9,31 @@ Window {
|
|||||||
visible: true
|
visible: true
|
||||||
title: "WIFI Picker"
|
title: "WIFI Picker"
|
||||||
|
|
||||||
property var model
|
|
||||||
|
|
||||||
signal scanNetworks()
|
signal scanNetworks()
|
||||||
|
|
||||||
Button {
|
Button {
|
||||||
id: scanbutton
|
id: scanbutton
|
||||||
text: "Scan for networks"
|
text: "Scan for networks"
|
||||||
onClicked: window.scanNetworks()
|
onClicked: window.scanNetworks()
|
||||||
}
|
}
|
||||||
|
|
||||||
ListView {
|
ListView {
|
||||||
id: listview
|
id: listview
|
||||||
model: window.model
|
model: networksModel
|
||||||
width: 100
|
anchors.fill: parent
|
||||||
height: 200
|
// model: ListModel {
|
||||||
// model: ListModel {
|
// ListElement { name: "Item 1"; value: 10 }
|
||||||
// ListElement { name: "Item 1"; value: 10 }
|
// ListElement { name: "Item 2"; value: 20 }
|
||||||
// ListElement { name: "Item 2"; value: 20 }
|
// ListElement { name: "Item 3"; value: 30 }
|
||||||
// ListElement { name: "Item 3"; value: 30 }
|
// }
|
||||||
// }
|
|
||||||
|
|
||||||
delegate: Item {
|
delegate: Item {
|
||||||
height: 20
|
height: 20
|
||||||
required property string name
|
required property string name
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
text: parent.name
|
text: parent.name
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-4
@@ -18,9 +18,6 @@ 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
|
||||||
@@ -47,12 +44,18 @@ QVariant NetworksModel::data(const QModelIndex &index, int role) const
|
|||||||
|
|
||||||
void NetworksModel::scan()
|
void NetworksModel::scan()
|
||||||
{
|
{
|
||||||
|
beginInsertRows(QModelIndex(), this->rowCount(), this->rowCount());
|
||||||
|
|
||||||
QList<Network> networks = this->m_networkScanner.scanForNetworks();
|
QList<Network> networks = this->m_networkScanner.scanForNetworks();
|
||||||
for (const Network& network: networks)
|
for (const Network& network: networks)
|
||||||
{
|
{
|
||||||
qDebug() << "Got network: " << network.name() << Qt::endl;
|
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
|
QHash<int, QByteArray> NetworksModel::roleNames() const
|
||||||
|
|||||||
@@ -4,12 +4,14 @@
|
|||||||
#include <QtQuick/qquickitem.h>
|
#include <QtQuick/qquickitem.h>
|
||||||
#include <QtQuick/qquickview.h>
|
#include <QtQuick/qquickview.h>
|
||||||
#include <NetworkScanner.h>
|
#include <NetworkScanner.h>
|
||||||
|
#include <QQmlContext>
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QGuiApplication app(argc, argv);
|
QGuiApplication app(argc, argv);
|
||||||
|
|
||||||
NetworksModel model;
|
NetworksModel model;
|
||||||
|
model.scan();
|
||||||
qDebug() << "now has " << model.rowCount() << Qt::endl;
|
qDebug() << "now has " << model.rowCount() << Qt::endl;
|
||||||
|
|
||||||
QQmlApplicationEngine engine;
|
QQmlApplicationEngine engine;
|
||||||
@@ -20,9 +22,9 @@ int main(int argc, char *argv[])
|
|||||||
&app,
|
&app,
|
||||||
[]() { QCoreApplication::exit(-1); },
|
[]() { QCoreApplication::exit(-1); },
|
||||||
Qt::QueuedConnection);
|
Qt::QueuedConnection);
|
||||||
|
engine.rootContext()->setContextProperty("networksModel", &model);
|
||||||
engine.load(url);
|
engine.load(url);
|
||||||
|
|
||||||
|
|
||||||
QObject *rootObject = engine.rootObjects().first();
|
QObject *rootObject = engine.rootObjects().first();
|
||||||
if (!rootObject)
|
if (!rootObject)
|
||||||
{
|
{
|
||||||
@@ -30,11 +32,7 @@ int main(int argc, char *argv[])
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
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()));
|
||||||
|
|
||||||
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user