Hi!
I’m writing a program to show in real time the position of the planets in the ecliptic.
First, I have a ListView:
import QtQuick 2.0
Item {
width: 200
height: 400
ListView {
width: parent.width; height: 300
id: listView
anchors.fill: parent
highlight: Rectangle { color: "lightsteelblue"; radius: 5 }
focus: true
model: myModel
delegate: Rectangle {
height: 20
width: parent.width
Text {
text: display
font.pointSize: 12
}
}
}
}
Then, I have a QStringListModel:
class QalPlanetGroup;
class QStringListModel;
#include "qtquick2applicationviewer.h"
class Viewer : public QtQuick2ApplicationViewer
{
Q_OBJECT
public:
Viewer();
public slots:
void update();
private:
QalPlanetGroup *planetGroup;
QStringListModel *model;
};
As you can see in the following code, the data updates every second and every row is checked. If the position of the planet has changed, it sets the model’s row data. The problem is that the ListView doesn’t update, it keeps showing the same initial data, and I don’t know what to change to make it update it. In fact, I have the same program made of QWidgets and works perfectly well, but I want to port it to QML to be able to use it in my mobile phone.
@
#include <QStringListModel>
#include <QQuickView>
#include <QQmlContext>
#include <QTimer>
#include <qalplanetgroup.h>
#include “viewer.h”
#include <QDebug>
Viewer::Viewer()
{
model = new QStringListModel;
planetGroup = new QalPlanetGroup;
planetGroup->addMainPlanets();
planetGroup->computeData();
QDateTime dateTime = QDateTime::currentDateTimeUtc();
planetGroup->computeData(dateTime);
QStringList l = planetGroup->toStringList(”%n:\t
↧