Important: Please read the Qt Code of Conduct -

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);
        QPainter painter(&printer);
        painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform);
        m_userView->render( &painter );

    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.


  • Moderators

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

  • @artwaw I only saw the post on this site 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, 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