Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 81941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:32:20+00:00 2026-05-10T21:32:20+00:00

Can I put the painter into the class variables? : protected: QPainter *myPainter; …

  • 0

Can I put the painter into the class variables? :

protected: QPainter *myPainter;  ...  void MyWidget::paintEvent(QPaintEvent *event) {     myPainter = new QPainter(this); 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T21:32:21+00:00Added an answer on May 10, 2026 at 9:32 pm

    A new anser to address more reentrancy more specifically…

    danatel left the following comment to this message (in part):

    By reentrancy I mean this specific situation: 1) paintEvent handler saves a QPainter to a class variable. 2) paintEvent handler calls subroutines to draw something 3) one of the subroutines calls a Qt method 4) this Qt method generates another paintEvent recursively

    The answer to this is that it should likely be acceptable, unless you do something really odd. (And if you do something that odd, Qt will likely warn you or abort.) I think there might still be some confusion over what you mean by reentrant, but generating a paintEvent won’t stop the execution flow of the current action to immediately process that event. Instead (like all events), it will be queued up for later processing. As long as you aren’t doing multi-threading or calling processEvents, the execution order of the code while you are in one of your own functions should be very straightforward.

    As an example, let’s follow your steps and examine them in more detail.

    1. Foo::paintEvent() handler creates a QPainter and sets Foo::m_painter_p at it.
    2. Foo::paintEvent() calls Foo::paintAntarticaFlag().
    3. Foo::paintAntarticaFlag(): a) uses Foo::m_painter_p, then b) calls something that calls Foo::update(), then c) uses Foo::m_painter_p some more.
    4. Foo::update(), which is really a Qt method, generates a paintEvent for Foo.

    The above sequence is fine, since update creates an event, which means delayed processing. If instead you called Foo::repaint(), that would cause an immediate recursion into Foo::paintEvent(), which would either cause Qt to abort because you are creating more than 1 painter for the same object, or your program to abort because it eventually (you know, in a few hundred milliseconds) blew out the stack.

    If you are doing multiple threads and just want to trigger a redraw, you can still do that from the other thread, since it will just put a paintEvent on the queue to be handled by the proper thread at the proper time. If you are doing multiple threads and want to draw those flags using the same painter, well, don’t. Just don’t. In that case, you might consider drawing each flag to a shared image, and drawing that image where you are using the QPainter now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 75k
  • Answers 76k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer If you are using PHP5 (and you should be), take… May 11, 2026 at 2:55 pm
  • added an answer username is in the 3rd column. So you can do… May 11, 2026 at 2:55 pm
  • added an answer RewriteRule ^press/index.php/(.*) /press/$1 [R=301] May 11, 2026 at 2:55 pm

Related Questions

Can I put the painter into the class variables? : protected: QPainter *myPainter; ...
I have a C# class library that contains methods that need to be used
I'm currently working on a ray-tracer in C# as a hobby project. I'm trying
I'm working on a WinCE 6.0 system with a touchscreen that stores its calibration
I have put together a script which is very much like the flickr photostream

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.