Grazie a synasius ho capito....
bisogna includere nel cpp:
<< #include <QQmlContext> >>
ed aggiungere questa stringa:
<< auto* ctx = engine.rootContext(); >>
e aggiungere per ogni textinput
<< ctx->setContextProperty("view_id",VALORE); >>
dove view_id è un textedit:
<<
TextEdit {
id: id
x: 8
y: 30
width: 300
height: 20
font.pixelSize: 12
text: view_id
}
Così il mio codice è diventato:
<< //main.cpp
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>
#include <QSqlTableModel>
#include <QDebug>
#include <QObject>
#include <QQmlContext>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");
db.setDatabaseName("Nome_Db");
db.setUserName("root");
db.setPassword("mysql");
bool ok = db.open();
auto* ctx = engine.rootContext();
QSqlQuery query;
query.exec("SELECT * FROM upload;");
while (query.next()) {
ctx->setContextProperty("view_id", query.value(0).toInt());
ctx->setContextProperty("view_desc", query.value(1).toString());
ctx->setContextProperty("view_filename", query.value(2).toString());
ctx->setContextProperty("view_id_dip", query.value(3).toInt());
//qDebug() << id << descrizione << filename << id_dipendente;
}
return app.exec();
}
<< //MainForm.ui.qml
import QtQuick 2.6
Rectangle {
width: 360
height: 360
color: "gray"
TextEdit {
id: id
x: 8
y: 30
width: 300
height: 20
font.pixelSize: 12
text: view_id
}
TextEdit {
id: descrizione
x: 8
y: 60
width: 300
height: 20
font.pixelSize: 12
text: view_desc
}
TextEdit {
id: filename
x: 8
y: 90
width: 300
height: 20
font.pixelSize: 12
text: view_filename
}
TextEdit {
id: id_dipendente
x: 8
y: 120
width: 300
height: 20
text: view_id_dip
font.pixelSize: 12
}
}
Grazie ;)