Important: Please read the Qt Code of Conduct -


  • Hi
    I am using a QPainter object and call the begin and end methods.
    Both return a boolean and I wanted to know if there is a way of finding out(in code) why one these methods might return false?
    For example

    QPainter painter;
    if (!painter.begin(&printer))
        //What happened

  • Moderators

    Some of the reasons are right there in the documentation: QPainter::begin().
    Generally speaking begin() returns false when the underlying resources are unavailable - another painter is active on that device, trying to paint to a null device or image, underlying paint engine is uninitialized or non existing etc. For end() it's similar - either the painter in not active on any device or the underlying paint engine failed to end the operation for whatever reason.

    There is no API for getting the reason of failure of any of those as it would be hard to make one considering there are different paint engines and you can even make one yourself. It would have to be something really generic like a string, and having users parse that and basically expect every possible reason on every supported platform would not be a good API.

Log in to reply