Welcome, Guest. Please login or register.
Did you miss your activation email?

Author Topic: How to set QTableView data to the limereport file lrxml  (Read 4308 times)

plehmz

  • Newbie
  • *
  • Posts: 7
    • View Profile
How to set QTableView data to the limereport file lrxml
« 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,

Subst

  • Sr. Member
  • ****
  • Posts: 450
    • View Profile
Re: How to set QTableView data to the limereport file lrxml
« Reply #1 on: June 07, 2024, 12:31:43 pm »
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
Code: [Select]
report->designReport() to show LRDesigner, and your model must be shown in datasources

plehmz

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: How to set QTableView data to the limereport file lrxml
« Reply #2 on: June 07, 2024, 02:06:41 pm »
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.

plehmz

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: How to set QTableView data to the limereport file lrxml
« Reply #3 on: June 07, 2024, 02:09:02 pm »
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
Code: [Select]
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.

Arin Alex

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 1005
    • View Profile
Re: How to set QTableView data to the limereport file lrxml
« Reply #4 on: June 07, 2024, 04:54:08 pm »
Hi. You have to set datasource property on the databand that will point to the data source