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

Author Topic: Print image from Qt Creator c++ code  (Read 4158 times)

falcon

  • Newbie
  • *
  • Posts: 2
    • View Profile
Print image from Qt Creator c++ code
« on: March 16, 2018, 05:28:25 pm »
Hello everybody,

I'm a beginner with Qt and LimeReport and I try to print a picture from my c++ code to my Lime Report Template.

I already success to write a variable from my c++ code to the PDF file with the template.
To do that I created a new "Report variables" in "Data Browser -> Variables". Then, I created a new "TextItem" and in the "Property Name" to "content", I write "$V{number}" to reference the "Report variables" with the same name. I don't know if it's right but it's works.

You can see my code.

Code: [Select]
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow),
    report(new LimeReport::ReportEngine),
{
    ui->setupUi(this);
    this->number = 0;
    this->report = new LimeReport::ReportEngine(parent);
    this->report->loadFromFile("lrTemplate01.lrxml");
}

void MainWindow::on_pushButton_clicked()
{
    QPixmap p = ui->qgvChart->grab();

    this->report->dataManager()->setReportVariable("number", this->number++);
    p.save("a.png", "PNG", 100);
    this->report->previewReport();
}

void MainWindow::on_pushButton_2_clicked()
{
    this->report->printToPDF("report");
}


The question is, how can I do that for a picture.
I have "p" that is my "QPixmap" and I would like to do something like:
Code: [Select]
this->report->dataManager()->setReportVariable("image", p);
But I have no idea how it's possible and what kind of "variables" I have to create on the "Line Report Designer".

Somebody can please help me ?

Arin Alex

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 1005
    • View Profile
Re: Print image from Qt Creator c++ code
« Reply #1 on: March 18, 2018, 12:18:27 pm »
Hello!
I read your question and thought why not. In the result I made changes to the develop branch and now the pictures can be transferred to the report via a variable.

falcon

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Print image from Qt Creator c++ code
« Reply #2 on: March 19, 2018, 02:53:10 pm »
Hello Alex,

First, I would like to thank you a lot for your help.
That was quick and efficient.  ;D

I tried to download the "develop branch" from git and build it.
Everythings seams to works good but when I compile my soft I have an error:

C:\LimeReport-master\Lib\include\lrglobal.h:49: erreur : QScriptEngine: No such file or directory

The error is there:
Code: [Select]
#ifdef USE_QJSENGINE
//#include <QJSEngine>
#include <QQmlEngine>
#else
#include <QScriptEngine>   <==(!)=====(!)======(!)== (line 49)
#endif

What is the problem ?

Arin Alex

  • Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 1005
    • View Profile
Re: Print image from Qt Creator c++ code
« Reply #3 on: March 22, 2018, 04:10:35 am »
Hi!
I made some new changes in develop branch.
You can try again to get sources and build it.
Important: before build new sources clean project and run qmake.