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

  • SEARCH
  • Home
  • 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 7772453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:53:42+00:00 2026-06-01T16:53:42+00:00

I have a QGraphicsScene with about 1000 QGraphicsItems, which are actually physics items. Each

  • 0

I have a QGraphicsScene with about 1000 QGraphicsItems, which are actually physics items. Each frame they advance, check for collisions, and resolve those collisions, among other things. I would really like to have the physics multithreaded.

It is my understanding that the QGraphics classes are not thread-safe. Meaning, they can only be called from the main thread. Does this force me to send the final item properties (x, y, rotation) each frame to the main thread using a signal/slot mechanism, and then use a main thread method to actually update the QGraphicsItems? Or is there an easier way to do this?

What follows is just a hypothesis: Could I use QtConcurrent to run a method on my list of QGraphicsItems? If I use a QMutex in my QGraphicsItem paint method and a QMutex in my physics method (that will change properties of my QGraphicsItem), would this guarantee that only one thread is reading/writing each QGraphicsItem at any one moment in time?

  • 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. Editorial Team
    Editorial Team
    2026-06-01T16:53:43+00:00Added an answer on June 1, 2026 at 4:53 pm
    1. If I use a QMutex in my QGraphicsItem paint method and a QMutex in my
      physics method (that will change properties of my QGraphicsItem),
      would this guarantee that only one thread is reading/writing each
      QGraphicsItem at any one moment in time?

      No, it wouldn’t. QGraphicsItem used heavily while drawing, not only paint method called. Look, for example, here. Even if it could work, it would be ugly solution, because apparently, QGraphicsItem can be used not only for painting.

    2. Does this force me to send the final item properties (x, y, rotation)
      each frame to the main thread using a signal/slot mechanism, and then
      use a main thread method to actually update the QGraphicsItems? Or is
      there an easier way to do this?

      Yes, you have to move item changing process to main thread. You actually have some alternatives:

      • Use signals/slots mechanism, as you mentioned.
      • Use meta-calls with QueuedConnection
      • Send custom events.

      Don’t forget, that you has BlockingQueuedConnection, if you want to wait for painting finished.

      Also, you can use all this stuff with QtConcurent.

    Actually, it is not so difficult to manage. It is much safer and easier, than ensuring thread safety manually.

    The bigger problem is that you probably may fail even when trying to read items (using only const memebers, for example) in worker thread.

    As far, as QGraphicsItem is not thread safe, even reading is not. And my experience of multithread app development in Qt tells me, that if something bad can happen, it will happen.

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

Sidebar

Related Questions

I need to view QGraphicsScene in 2 QGraphicsViews with condition that they have different
I have about 150 QGraphicsLineItems in a QGraphicsScene, and I want to rotate them,
I have an QGraphicsscene on which there is a picture QPixmap into QGraphicsView. I
I have a huge array of 2D points (about 3 millions of pairs), which
I have a QGraphicsScene in which I add a QGraphicsItem. Inside the QGraphicsItem, I
I have been studying the Qt Quarterly article about QGraphicsScene and OpenGL for the
I have a QGraphicsScene on which I would like to draw some special curves.
In my application I have QGraphicsScene with pixmap added and all is viewed in
I have a QGraphicsScene that I want to copy and append to the start
In Qt, I have created a QGraphicsScene as shown below. m_scene = new QGraphicsScene(0,0,152,720);

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.