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. Using QGraphicsItem in DLL.
Forum Updated to NodeBB v4.3 + New Features

Using QGraphicsItem in DLL.

Scheduled Pinned Locked Moved General and Desktop
6 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.
  • G Offline
    G Offline
    Grinchman
    wrote on last edited by
    #1

    Hello.
    I have little GUI project. I use there QGrapchicScene with QGraphicsItems on it. And this project is built as DLL. Project which uses my DLL as plugin is able to call dll-interfaces for my dll not only from MainThread. It means that some updatings or manipulatings with QGraphicsItems may occure from WorkThreads. According to docs, QGraphicsItems doesn`t allow this.

    Q1: How to prevent this behaviour?
    Q2: Is there some "strategy" for developing GUI dll in multithreaded environment?

    Thanks in advance for helping!

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Franzk
      wrote on last edited by
      #2

      You could post events to yourself notifying you of changes. This guarantees you are always running from the same thread, most likely the main/GUI thread.

      "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dialingo
        wrote on last edited by
        #3

        Define a class which has a slot for every graphics operation you want to trigger. This class must reside in the GUI thread. Now it is safe to trigger these slots from a worker thread via queued conection.

        By the way: A queued connection can be triggered without defining a connection first:
        QMetaObject::invokeMethod(guiObject, "drawMyFancyLine", Qt::QueuedConnection);

        1 Reply Last reply
        0
        • G Offline
          G Offline
          Grinchman
          wrote on last edited by
          #4

          Thanks guys for answers. But before I implemented that solution developers of Main Project have changed behaviour of theirs project and now it calls my dll only from MainThread. Could I be happy? Yes! But I came to a new problem. All works fine with Qt 4.7.3, but when we use Qt 4.5.3 my DLL is 'blocking'! Main app calls my dll, it creates windows but nothing is happening then - I cant push buttons, repaint isnt happening and etc...
          I have a piece of code from Main app which shows how app manages window events (messages). Maybe it would be useful to understand what`s wrong with it...
          @while(buckets_rendered<numRects && events!=0)
          {
          while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
          {
          TranslateMessage(&msg);
          DispatchMessage(&msg);
          }

          stat = MsgWaitForMultipleObjects(numHandles, handles, FALSE, INFINITE, QS_ALLINPUT);
          if(stat == (WAIT_OBJECT_0 + numHandles))
          {
          continue;
          }
          else // message comes from the events
          {
          id = stat - WAIT_OBJECT_0;
          --events;

          // ...
          }
          }@

          1 Reply Last reply
          0
          • F Offline
            F Offline
            Franzk
            wrote on last edited by
            #5

            Did you try pinpointing what exactly the application is blocking on?

            "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • G Offline
              G Offline
              Grinchman
              wrote on last edited by
              #6

              Im not sure about the blocking point, but I have important additional information. It seems that paintEvent is blocked somehow. Evenmore, when I click left mouse button on some application button nothing is happening, but when next I click right mouse button some events is occures and I see an effect from first left mouse button click and an effect from right button click...Why only right mouse button click force repaint? Im confused...

              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