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

Author Topic: dynamic path to data base  (Read 1732 times)

solitarywolf

  • Newbie
  • *
  • Posts: 4
    • View Profile
dynamic path to data base
« on: May 26, 2020, 10:13:41 PM »
Hi guys, I am using this report generator and I managed to design my report and then link it to my form, I managed to show the report from a button, my question is how do I change the path from where I have the database dynamically, that is, to the move the database or when distributing my app to another computer, since I have to be editing the lrxml file, to change the path manually, I am using a SQlite db for now. Thanks, I hope your suggestions.


code of my button where I show the report, I have it added as a resource of my application...
Code: [Select]
void Widget::on_btnReporte_clicked()
{
  QFile reportName(":/reports/ejemplo.lrxml");
  if(!reportName.open(QIODevice::ReadOnly|QIODevice::Text))
    {
      QMessageBox::critical(this,qApp->applicationName(),
                            "Ocurrio un error al cargar el reporte.0\n"+reportName.errorString());
      return;
    }
  _report=new LimeReport::ReportEngine(this);
  _report->loadFromFile(reportName.fileName());
  _report->previewReport();
}


Code: [Select]
<datasourcesManager ClassName="LimeReport::DataSourceManager" Type="Object">
      <objectName Type="QString">datasources</objectName>
      <connections Type="Collection">
        <item ClassName="LimeReport::ConnectionDesc" Type="Object">
          <objectName Type="QString"></objectName>
          <name Type="QString">reporte</name>
          <driver Type="QString">QSQLITE</driver>
          [b]<databaseName Type="QString">D:/QtProjects/BranchExe/db/dbejemplo.db</databaseName>[/b]
          <userName Type="QString"></userName>
          <password Type="QString" Value=""/>
          <host Type="QString"></host>
          <autoconnect Type="bool" Value="1"/>
          <keepDBCredentials Type="bool" Value="1"/>
          <port Type="int" Value="-1"/>
        </item>
      </connections>

This is the part I am referring to, in the databaseName tag, how do I get that path changed, without having to do it manually.

Arin Alex

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 992
    • View Profile
Re: dynamic path to data base
« Reply #1 on: May 26, 2020, 11:02:58 PM »
Hi!
There are some ways to do it.
If you create a connection in your application with the same name as used in the report template it will be used instead.
Also, in the latest version at GitHub, you can use a variable in the database name and initialize it from your application.

solitarywolf

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: dynamic path to data base
« Reply #2 on: May 26, 2020, 11:59:16 PM »
well I did not understand that, what happens is that, I use the designer to create the report, and just call it from my app, in my application I get the address of the database with qApp-> applicationDirPath (). append (" /db/dbejemplo.db "), but this as reflected in the report, a practical example would be good, if possible.

Arin Alex

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 992
    • View Profile
Re: dynamic path to data base
« Reply #3 on: May 28, 2020, 11:51:12 AM »
After you get the database path, you can initialize the variable using this value like this:
Code: [Select]
report->dataManager()->setReportVariable("DATABASE",databasePath);Then in a report template, you can use the variable in connection describer in the field "database" like this: $V{DATABASE}

solitarywolf

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: dynamic path to data base
« Reply #4 on: May 28, 2020, 11:06:50 PM »
great friend, thanks I solved my problem.