Allora: principalmente la difficoltà stà nel fatto che mi devo ancora "ambientare" nelle malità di render qml/quick comunque direi che al passo 5 siamo anche arrivati al dunque e non serviva fare altro. riporto il codice corretto:
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QtQuickControls2>
#include <QtSql>
#include <QtGui/QGuiApplication>
#include <QtCore/QDir>
#include <QtQuick/QQuickView>
#include <QtQml/QQmlEngine>
#include <QtQml/qqml.h>
#include "shared/shared.h"
#include <QtCharts>
#include <QtDataVisualization>
#include <QAbstractTableModel>
#include <QtMessageHandler>
#include <QMessageBox>
#include <QMessageLogContext>
#include <QMessageLogger>
#include <QDebug>
#include <QQmlEngine>
#include "sqlquerymodel.h"
using namespace QtCharts;
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("/home/pc/Qt/TestApp/DataBase/TestAnalyticsDB");
if(db.open()) {//{ QMessageBox::information(nullptr,"Ok","Connection ok");
qDebug() << "connessione ok";
}
else qDebug() << "connessione FALLITA";//QMessageBox::information(nullptr,"Error","some error.");
SqlQueryModel *UserRegistry = new SqlQueryModel(nullptr);
UserRegistry->setQuery("SELECT * FROM userData");
SqlQueryModel *AdmRegistry = new SqlQueryModel(nullptr);
AdmRegistry->setQuery("SELECT * FROM admData");
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("userModel", UserRegistry); /* the trick */
engine.rootContext()->setContextProperty("admModel", AdmRegistry); /* second query table model */
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
return app.exec();
}
e poi nel codice ui.qml alla sezione tableView:
C.TableView {
id: tableViewUser
x: 8
y: 8
width: 1152
height: 244
anchors.right: parent.right
anchors.left: parent.left
anchors.top: parent.top
verticalScrollBarPolicy: 2
clip: true
model: userModel /* the trick */
C.TableViewColumn {
title: "User id"
role: "IDuser"
width: title.length * 10
visible: true
}
/* other column*/
/* second table*/
C.TableView {
id: tableViewData
x: 0
y: 250
width: 1168
height: 433
anchors.right: parent.right
anchors.left: parent.left
anchors.top: parent.bottom
verticalScrollBarPolicy: 2
clip: true
model: admModel /* second query table model */
C.TableViewColumn {
title: "Sensore 1"
role: "sens1"
width: title.length * 15
}
e questo è tutto .... immagino che creando una classe specifica ( modificando SqlQueryModel per esempio) sarà facile ricreare layout diversi e tabelle "relazionali".