Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Mysql and PDF
Forum Updated to NodeBB v4.3 + New Features

Mysql and PDF

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lima_will
    wrote on last edited by
    #1

    personal

    Need a little help need to get data from a select and play in a pdf. The two separated can normally do, ie create a pdf with data "fixed" quiet and will make the connection to the database, select, delete, upgrade is also quiet.
    Now the two together still can not, I tried to do this:
    @
    QPrinter printer;
    QString dt_venda,cod_venda,valor,cod_arm,forma;
    printer.setColorMode(QPrinter::Color);
    printer.setOutputFormat(QPrinter::PdfFormat);
    printer.setOutputFileName("/home/will/Vendas_do_dia.pdf");
    QPainter painter;
    QImage imagem ("/home/will/foto_dia.jpg");
    if (! painter.begin(&printer)) { // failed to open file
    qWarning("failed to open file, is it writable?");
    }
    painter.drawImage(10,10,imagem);
    painter.drawText (400,50,Data);
    painter.drawText(10,60,"____________________________________________________________________________________");
    Conexao();
    QSqlQuery qry;
    qry.prepare("select dt_venda,codVenda,valor,codArm,form_pag from vendas where dt_venda= :data");
    qry.bindValue(":data",Data);
    qry.exec();
    while(qry.next())
    {
    dt_venda = qry.value(0).toString();
    cod_venda = qry.value(1).toString();
    valor = qry.value(2).toString();
    cod_arm = qry.value(3).toString();
    forma = qry.value(4).toString();

            painter.drawText(10,90,dt_venda);
            painter.drawText(10,110,cod_venda);
            painter.drawText(10,130,valor);
            painter.drawText(10,150,cod_arm);
            painter.drawText(10,180,forma);
        }
       painter.end();
      QDesktopServices::openUrl(QUrl("/home/will/Vendas_do_dia.pdf"));@
    

    Only it's not working printing the pdf file ie back empty any suggestions on how to get that impression?

    1 Reply Last reply
    0
    • H Offline
      H Offline
      Hareen Laks
      wrote on last edited by
      #2

      Recently, I did the same thing.

      But your problem is not very clear to me.

      Are you getting empty pdf page?

      First check the values of the variables dt_venda ,cod_venda ,valor , cod_arm , forma not empty.

      And try to use point to printer instead of reference. (here : painter.begin(&printer))

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved