Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[solved]How to catch error when printing QTextDocument to pdf when pdf is open?



  • Hi!
    I am printing a QTextDocument to a pdf with the following command:
    @doc.print(&printer);@

    It runs fine except when the pdf is already opened in a viewer (e.g. foxit reader), which makes sense as the printer doesn't have write permissions probably. Unfortunately, I haven't figured out how to catch this error, as the .print function is void. The only thing I see is the following on the console:
    @QPainter::begin(): Returned false@

    How can I catch this?
    Thank you for any help!


  • Lifetime Qt Champion

    Hi,

    Maybe using QDir to list writable files before printing might work

    Hope it helps



  • Thank you for you hint!
    The way I do it now is to try to open the file in write mode. If it is successful, I can continue with to printing, otherwise I throw an error.
    Thank you again for pointing me into this direction!


Log in to reply