Strange errors from paintEngine

  • In an app I've been developing, I've started to get a huge number of error messages related to QWidget::paintEngine and QPainter. I just noticed them for the first time this evening, bug am not really certain when they started. The errors are of the form shown below, and just about anything I do with the app triggers many of these errors.

    How do I start to find the ultimate source of these errors? I haven't a clue what part of the app uses these components.

    For reference, the the app is essentially a collection of text widgets - QLabels, QPushButtons,QLineEditors, QComboBoxes, QTextEditors, etc. packaged into various layout widgets.

    What sorts of components need/use paintEngine and QPainter? I've not previously been aware of them.

    Thanks for any clues where to begin.

    QWidget::paintEngine: Should no longer be called
    QPainter::begin: Paint device returned engine == 0, type: 1
    QPainter::translate: Painter not active
    QPainter::save: Painter not active
    QPainter::setClipRect: Painter not active
    QPainter::pen: Painter not active
    QPainter::setPen: Painter not active
    QPainter::pen: Painter not active
    QPainter::setPen: Painter not active
    QPainter::restore: Unbalanced save/restore
    QPainter::setPen: Painter not active

  • Lifetime Qt Champion

    @drmhkelley Do you call anywhere in your app directly? Or do you use any third party libraries in your project?

  • I don't knowingly call paint

  • Lifetime Qt Champion

    @drmhkelley What about my second question?

  • I don't knowingly call paintEngine anywhere in my code. I do use third party libraries - some really third party and some where I am the third party. None of those libraries have any reason to interact with paintEngine directly.

  • Lifetime Qt Champion

    @drmhkelley Can you reproduce this issue with a simple Qt GUI application?

  • Working on that part. I just ran another of my apps and it does not exhibit this behavior. It uses most of the same basic components and libraries, plus a bunch more. The second is a plotting app I use a lot, so I thought it might place more demands on many aspects of the the graphics sub-components. It does use most of the same text widgets.

  • Lifetime Qt Champion

    @drmhkelley I think one of the libs you're using causes this warnings. Try to disable one by one until there are no warnings any-more, then you know where the problem is.

  • Hi, have you ever used QPainter in any widgets then?

  • Lifetime Qt Champion

    @drmhkelley said

    How do I start to find the ultimate source of these errors?

    You can also use the message handler trick

    where you redirect all messages to your own function and there do a if/string compare with a breakpoint.
    So when your breakpoint is triggered, you can see where the message comes from via the call stack.

  • @Bonnie - I have never used QPainter, at least not directly. I found reference to in in one 3rd party package I use quite often, but it is not used in my the app currently under consideration. And one app that does use that package does not exhibit the symptom.

  • @mrjj - Thank you for this suggestion. I have not tried this before, but it does sound like it will get me much closer much quicker.

  • @drmhkelley
    I'm not sure what is your situation here, but from my experience, this kind of error usually caused by calling something like

    QPainter p(this);
    //use p to draw something

    outside the paintEvent of a widget.

  • @mrjj - Again, thanks very much for this suggestion. Solved my problem immediately. Had I been aware of this in the past, I would have addressed several glitches much more easily. Will now be a standard part of my toolkit.

    As is too often the case, it solved my immediate problem, but now has me curious why I only now discovered that I should have been aware of the underlying problem long ago.

    Detailed info follows.

    It is often the case that the out-of-the-box QWidgets don't offer quite the capabilities I expect, so I've put wrappers around several to better meet my expectations. In this particular case, I wanted to intercept a couple of QEvents to process on my own while passing the bulk of QEvents on to Qt. I've done this for about a dozen QWidgets, including QLineEdit and QTextEdit. My version of the former I use a lot, the latter much less often.

    My mistake was that for all such wrapper widgets, I passed the intercepted to QWidget, not specifically to QLineEdit or QTextEdit as I should have. In any event, Qt was quite unhappy that I passed events intended specifically for QTextEdit to QWidget.

    I'm not surprised that this mistake would lead to unexpected outcomes. I am surprised that doing so for QTextEdit led to such different outcomes that QLineEdit, QLabel, QPushButton, QDateEdit, QSpinBox, QCalendar, QComboBox, etc.

Log in to reply