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. Could slot function and mouseMoveEvent be possibly excuted concurrently in a muti-cores machine?

Could slot function and mouseMoveEvent be possibly excuted concurrently in a muti-cores machine?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 4 Posters 899 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.
  • LimerL Offline
    LimerL Offline
    Limer
    wrote on last edited by Limer
    #1
    class MyScene : public QGraphicsScene
    {
        ...
    
        MyScene()
        {
            ...
    
            m_mouseEventEnabled = false;
            thread.start();
            connect(&thread, SIGNAL(finished()), this, SLOT(mouseEventEnabledSlot()));
    
            ...
        }
        
        ...
    
    public slots:
    
        void mouseEventEnabledSlot()
        {
            m_mouseEventEnabled = true;
        }
    
    protected:
    
        void mouseMoveEvent(QGraphicsSceneMouseEvent* event)
        {
            if (m_mouseEventEnabled)
            {
                do_mouse_move_thing();
            }
        }
        
    private:
    
        bool m_mouseEventEnabled;
        MyThread thread;
    
        ...
    }
    

    Just as the code show, when the thread finishes, m_mouseEventEnabled will be set to true, for variable m_mouseEventEnabled, this is a writing behavior,

    but the m_mouseEventEnabled in function mouseMoveEvent may always do a reading behavior,

    The program will be run in a muti-cores machine, and what I want to know is that whether the two behaviors can possibly excute concurrently?

    ( I know little about the underlying implementation mechanism in Qt, but after I google the relevant articles, I think it will never happen, just my plain view).

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      change bool m_mouseEventEnabled; to std::atomic_bool m_mouseEventEnabled;. The rest should work

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      LimerL 1 Reply Last reply
      3
      • VRoninV VRonin

        change bool m_mouseEventEnabled; to std::atomic_bool m_mouseEventEnabled;. The rest should work

        LimerL Offline
        LimerL Offline
        Limer
        wrote on last edited by
        #3

        @VRonin What you mean is the two behaviors can be excuted concurrently ?

        jsulmJ 1 Reply Last reply
        0
        • LimerL Limer

          @VRonin What you mean is the two behaviors can be excuted concurrently ?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Limer said in Could slot function and mouseMoveEvent be possibly excuted concurrently in a muti-cores machine?:

          What you mean is the two behaviors can be excuted concurrently ?

          yes

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • JKSHJ Offline
            JKSHJ Offline
            JKSH
            Moderators
            wrote on last edited by
            #5

            Normally, a widget's slot functions and event functions are run in the GUI thread.

            It is possible to run function concurrently from mouseMoveEvent() by running the function in a different thread. However, it is best to implement that function in a different class (unless you really really know what you are doing)

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            1 Reply Last reply
            2

            • Login

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