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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - Michaelszh

Pages: [1]
1
Hi
It's hard to say :) Your compiler knows it better :)
What I see at once and it's alarming me LimeReport::ReportEngine instance is created but not deleted  - it is memory leak.
Another part of the code, as I understand it, you've got from the demo and it is correct
Can I ask you why you use callbackDatasource instead sending a model to LimeReport ?

Hi, Alex

Because I don't know how to sending a model to LimeReport,can you help me?
thank you.

Is it like the following code?The code compiler is no problem, but run error, I was using limereprot in the MFC.

LimeReport::ReportEngine *report = new LimeReport::ReportEngine(m_pWnd);
   QSqlDatabase db = QSqlDatabase::addDatabase(m_strDbType);
   db.setHostName(m_strHostName);
   db.setDatabaseName(m_strDbName);
   db.setUserName(m_strUserName);
   db.setPassword(m_strPassword);
   if (db.open())
   {
      m_customers = new QSqlQuery(m_strQuerySql, db);
      QSqlQueryModel* customersModel = new QSqlQueryModel();
      customersModel->setQuery(m_strQuerySql);
      report->dataManager()->addModel("ds1", customersModel, true);

      report->loadFromFile(m_strReprotName);
      report->previewReport();
                delete customersModel;
   };
   delete report;

The following code works fine

   QWinWidget *pWidget = new QWinWidget(this);
   LimeReport::ReportEngine *report = new LimeReport::ReportEngine(pWidget); //to create reportengine
   report->loadFromFile("myfirstrpt.lrxml");// to load report template file
   report->previewReport();// to generate report and preview

2
Hello all,
I would like to dynamically load data from the mysql database to the report, the following code correct?

void CShowLimeReport::PreviewReport()
{
   LimeReport::ReportEngine *report = new LimeReport::ReportEngine(m_pWnd);
   QSqlDatabase db = QSqlDatabase::addDatabase(m_strDbType);
   db.setHostName(m_strHostName);
   db.setDatabaseName(m_strDbName);
   db.setUserName(m_strUserName);
   db.setPassword(m_strPassword);
   if (db.open())
   {
      m_customers = new QSqlQuery(m_strQuerySql, db);
      LimeReport::ICallbackDatasource * callbackDatasource = report->dataManager()->createCallbackDatasouce(m_strDatasourceName);
      QObject::connect(callbackDatasource, SIGNAL(getCallbackData(LimeReport::CallbackInfo, QVariant&)), m_pWnd, SLOT(slotGetCallbackData(LimeReport::CallbackInfo info, QVariant &data)));
      QObject::connect(callbackDatasource, SIGNAL(changePos(const LimeReport::CallbackInfo::ChangePosType&, bool&)), m_pWnd, SLOT(slotChangePos(const LimeReport::CallbackInfo::ChangePosType &type, bool &result)));
      report->loadFromFile(m_strReprotName);
      report->previewReport();
   };
}


void CShowLimeReport::slotGetCallbackData(LimeReport::CallbackInfo info, QVariant &data)
{
   if (!m_customers) return;
   prepareData(m_customers, info, data);
}

void CShowLimeReport::prepareData(QSqlQuery* ds, LimeReport::CallbackInfo info, QVariant &data)
{
   switch (info.dataType) {
   case LimeReport::CallbackInfo::ColumnCount:
      data = ds->record().count();
      break;
   case LimeReport::CallbackInfo::IsEmpty:
      data = !ds->first();
      break;
   case LimeReport::CallbackInfo::HasNext:
      data = ds->next();
      ds->previous();
      break;
   case LimeReport::CallbackInfo::ColumnHeaderData:
      if (info.index < ds->record().count())
         data = ds->record().fieldName(info.index);
      break;
   case LimeReport::CallbackInfo::ColumnData:
      data = ds->value(ds->record().indexOf(info.columnName));
      break;
   default: break;
   }
}

void CShowLimeReport::slotChangePos(const LimeReport::CallbackInfo::ChangePosType &type, bool &result)
{
   QSqlQuery* ds = m_customers;
   if (!ds) return;
   if (type == LimeReport::CallbackInfo::First) result = ds->first();
   else result = ds->next();
}

Pages: [1]