LimeReport Forum
General Category | Основное => Discussion | Обсуждение => Topic started by: plehmz on June 07, 2024, 09:37:16 am
-
I want to set QTableView data to Lime report, I tried with this code void MainWindow::loadJsonData()
{
QFile file(":/data/sample.json");
if (!file.open(QIODevice::ReadOnly))
{
qWarning("Couldn't open the file.");
return;
}
QByteArray data = file.readAll();
QJsonDocument document = QJsonDocument::fromJson(data);
QJsonArray jsonArray = document.array();
model->setColumnCount(3);
model->setHeaderData(0, Qt::Horizontal, "Name");
model->setHeaderData(1, Qt::Horizontal, "Age");
model->setHeaderData(2, Qt::Horizontal, "City");
for (const QJsonValue & value : jsonArray)
{
QJsonObject obj = value.toObject();
QList<QStandardItem *> items;
items.append(new QStandardItem(obj["name"].toString()));
items.append(new QStandardItem(QString::number(obj["age"].toInt())));
items.append(new QStandardItem(obj["city"].toString()));
model->appendRow(items);
}
}
void MainWindow::on_generateReportButton_clicked()
{
report->loadFromFile(":/reports/sample_report.lrxml");
report->dataManager()->addModel("jsonData", model, true);
report->previewReport();
}
but I don't know how to handle with limereport designer,
-
Hi!
QTableView dot't store any data it's own.
The data exists in the model.
This model You have been added to report.
Now You can just call report->designReport()
to show LRDesigner, and your model must be shown in datasources
-
Subst, thank you, I tried and succeeded , I saw the model in the data sources panel, and When I tried with columns, it shows only the first item of the model, how can I achieve this to show all items which I set with qt created app.
-
Hi!
QTableView dot't store any data it's own.
The data exists in the model.
This model You have been added to report.
Now You can just call report->designReport()
to show LRDesigner, and your model must be shown in datasources
thank you, I tried and succeeded , I saw the model in the data sources panel, and When I tried with columns, it shows only the first item of the model, how can I achieve this to show all items which I set with qt created app.
-
Hi. You have to set datasource property on the databand that will point to the data source