Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Twice QPainter on same QWindow causes crash
QtWS25 Last Chance

Twice QPainter on same QWindow causes crash

Scheduled Pinned Locked Moved Solved General and Desktop
qpainterqwindowcrash
5 Posts 3 Posters 2.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Harry123
    wrote on 23 Feb 2016, 15:35 last edited by Harry123
    #1

    By mistake I have created twice QPainter on the same QWindow, causing a crash when calling setBrush on the second one.

    The crash occurs inside QPainter::setBrush when calling QRasterPaintEngine::brushChanged, because in the line :

     QRasterPaintEngineState *s = state();
    

    the variable s is returned as zero (0), resulting in a crash when it is used.

    I have corrected my mistake and do not do that any more.
    However, I have not found it mentioned in the documentation that two QPainters are not allowed, so I'm wondering if this is a bug, or a feature that needs to be documented. In the later case, a more graceful error might also be useful.

    K H 2 Replies Last reply 23 Feb 2016, 19:06
    0
    • H Harry123
      23 Feb 2016, 15:35

      By mistake I have created twice QPainter on the same QWindow, causing a crash when calling setBrush on the second one.

      The crash occurs inside QPainter::setBrush when calling QRasterPaintEngine::brushChanged, because in the line :

       QRasterPaintEngineState *s = state();
      

      the variable s is returned as zero (0), resulting in a crash when it is used.

      I have corrected my mistake and do not do that any more.
      However, I have not found it mentioned in the documentation that two QPainters are not allowed, so I'm wondering if this is a bug, or a feature that needs to be documented. In the later case, a more graceful error might also be useful.

      K Offline
      K Offline
      kshegunov
      Moderators
      wrote on 23 Feb 2016, 19:06 last edited by
      #2

      @Harry123
      Is it possible you're trying to paint when you're not allowed to?
      For the QWindow class there's the limitation:

      The application can start rendering as soon as isExposed() returns true, and can keep rendering until it isExposed() returns false. To find out when isExposed() changes, reimplement exposeEvent(). The window will always get a resize event before the first expose event.

      while for widgets you're supposed to paint inside the paint events:

      Warning: When the paintdevice is a widget, QPainter can only be used inside a paintEvent() function or in a function called by paintEvent().

      Kind regards.

      Read and abide by the Qt Code of Conduct

      H 1 Reply Last reply 23 Feb 2016, 20:57
      0
      • K kshegunov
        23 Feb 2016, 19:06

        @Harry123
        Is it possible you're trying to paint when you're not allowed to?
        For the QWindow class there's the limitation:

        The application can start rendering as soon as isExposed() returns true, and can keep rendering until it isExposed() returns false. To find out when isExposed() changes, reimplement exposeEvent(). The window will always get a resize event before the first expose event.

        while for widgets you're supposed to paint inside the paint events:

        Warning: When the paintdevice is a widget, QPainter can only be used inside a paintEvent() function or in a function called by paintEvent().

        Kind regards.

        H Offline
        H Offline
        Harry123
        wrote on 23 Feb 2016, 20:57 last edited by Harry123
        #3

        @kshegunov

        The problem is not that simple - the painting is now ok since I started using only one painter. In any case, a crash is always to be avoided.

        The isExposed() limitation is true, but logic says that an unexposed window does not get paint events. But I digress - this has no bearing on the crash.

        Very kind regards.

        1 Reply Last reply
        0
        • H Harry123
          23 Feb 2016, 15:35

          By mistake I have created twice QPainter on the same QWindow, causing a crash when calling setBrush on the second one.

          The crash occurs inside QPainter::setBrush when calling QRasterPaintEngine::brushChanged, because in the line :

           QRasterPaintEngineState *s = state();
          

          the variable s is returned as zero (0), resulting in a crash when it is used.

          I have corrected my mistake and do not do that any more.
          However, I have not found it mentioned in the documentation that two QPainters are not allowed, so I'm wondering if this is a bug, or a feature that needs to be documented. In the later case, a more graceful error might also be useful.

          H Offline
          H Offline
          Harry123
          wrote on 5 Mar 2016, 12:54 last edited by
          #4

          I have posted this as bug : QTBUG-51624.

          1 Reply Last reply
          0
          • C Offline
            C Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on 5 Mar 2016, 18:07 last edited by
            #5

            It's not very well exposed, but this is actually documented in QPainter::begin():

            Warning: A paint device can only be painted by one painter at a time.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved