Create PDF from SQL data



  • Hello I saw this on a forum this is what I want to do but in that forum no one could solve this. I already try and edit his code but I got the same result. Hope someone can solve this. Thank you! :)

    "Hi all,
    I'am writing an application that takes data from a sqlite database and show it thanks to a qtableview. I would like now to add a button export which export the data displayed in this view to a PDF file.
    Here is the slot I wrote:

    Qt Code: Switch view
    //Exporter la liste des utilisateurs

    void PageUser::genPdfUser()
    {
        QString filename="users.pdf";
        //Param├Ętres d'impression
        QPrinter printer(QPrinter::HighResolution);
        printer.setOutputFileName(filename);
        printer.setPaperSize(QPrinter::A4);
        printer.setOutputFormat(QPrinter::PdfFormat);
     
        QPainter painter(&printer);
        painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform);
        m_userView->render( &painter );
        painter.end();
    }
    

    To copy to clipboard, switch view to plain text mode

    It doesn't work because when I click the button, I have no reaction. Hindly help me to corect it.

    thanks"


  • Moderators



  • Apart from double posting - where is painter.begin()?



  • @artwaw I only saw the post on this site http://www.qtcentre.org/threads/45584-export-qtableview-in-PDF. this is what I also want to do, in the link/post to that site I dont get any solution for this problem. I also try to use the code and modify it but I end up to error or it doesnt show anything to the printpreview or to the pdf.



  • @raven-worx no, I just copy the post to this link http://www.qtcentre.org/threads/45584-export-qtableview-in-PDF, because we have the same problem but there is no right solution to the link. I also try to modify it but as of now it's not working.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.