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. Weird error with QGraphicsItem sent from one thread to another.
Forum Updated to NodeBB v4.3 + New Features

Weird error with QGraphicsItem sent from one thread to another.

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 2.7k Views 1 Watching
  • 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.
  • J Offline
    J Offline
    JulienMaille
    wrote on last edited by
    #1

    Hello everyone, I'm facing a strange error.
    I have a processing thread that emit a few signal with QGraphicsItem* in parameters.
    Those signals are connected to the main thread which then add them to a QGraphicsViews.
    It works pretty well, until today. In addition to the ellipses and line I decided to add a QGraphicsTextItem*

    It still work, until the application loses focus. At this very specific moment, I get this error:
    !http://i.imgur.com/K6arKe3.png!

    Why does it crash with text items only? And why when the application loses focus?
    I'm lost!

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      You can't do that. QGraphicsItems are GUI objects, and can only be manipulated from the GUI thread. What you are trying to do is not supported, and can indeed lead to weird crashes and other undefined behaviour.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        JulienMaille
        wrote on last edited by
        #3

        But the thread is only responsible for creating the object. All the display is done in the main thread.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          AFAIK, that doesn't matter.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            giesbert
            wrote on last edited by
            #5

            Each QObject derived class belongs to the thread, that creates it (Thread affinity). So creating UI objects in a non UI thread is a no go.

            Nokia Certified Qt Specialist.
            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

            1 Reply Last reply
            0
            • J Offline
              J Offline
              JulienMaille
              wrote on last edited by
              #6

              But QGraphicsItem does not derive from QObject.

              1 Reply Last reply
              0
              • G Offline
                G Offline
                giesbert
                wrote on last edited by
                #7

                But it is a UI object, and it could be that it stores some data...
                Maybe some special cases for the text items...

                Nokia Certified Qt Specialist.
                Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                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