Skip to content
0
  • Recent
  • Tags
  • Popular
  • SAMSON Connect
  • Get SAMSON
  • Recent
  • Tags
  • Popular
  • SAMSON Connect
  • Get SAMSON
Collapse
SAMSON Forum
  1. Home
  2. Develop
  3. GUI
  4. Asynchronous event with QtConcurrent

Asynchronous event with QtConcurrent

Scheduled Pinned Locked Moved GUI
3 Posts 2 Posters 3.9k 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.
  • LaëtitiaL
    LaëtitiaL
    Laëtitia
    wrote on last edited by
    #1

    Hello,

    I wanted to run a asynchronous event on my samson app (I wanted to make the molecule vibrate and still be able to use something else).
    I did it using QtConcurrent tools, for this I had to change the content of CMakeLists.txt to add QtConcurrent library. It compiles fine but now my app is not visible anymore in SAMSON Debug. Is it because I changed CMakeLists.txt?
    Thanks in advance

    StephaneS 1 Reply Last reply
    0
    • LaëtitiaL Laëtitia

      Hello,

      I wanted to run a asynchronous event on my samson app (I wanted to make the molecule vibrate and still be able to use something else).
      I did it using QtConcurrent tools, for this I had to change the content of CMakeLists.txt to add QtConcurrent library. It compiles fine but now my app is not visible anymore in SAMSON Debug. Is it because I changed CMakeLists.txt?
      Thanks in advance

      StephaneS
      StephaneS
      Stephane
      wrote on last edited by Stephane
      #2

      Hi Laetitia,

      for efficiency reasons, the data graph is not thread-safe, so there might be issues when modifying the document from several distincts threads (e.g. in the history). So, when we want to do this type of things, we use a QTimer.

      For example you declare in a header a QTimer:

      QTimer animationTimer;
      

      and a slot:

      public slots:
          void animate();
      

      and in your source code (for example in the constructor), you connect the timer to a slot that will perform one update of the system:

      connect(&animationTimer, SIGNAL(timeout()), this, SLOT(animate()));
      animationTimer.setSingleShot(false); // make it repetitive
      

      Then, when you want to start the animation you do:

      animationTimer.start(20); // every 20 milliseconds
      

      And when you want to stop the animation you do:

      animationTimer.stop();
      

      In your animate() slot, you perform one step of the vibration. The QTimer will intersperse calls to your animate() function as regularly as possible, and SAMSON will still be able to process other events (keyboard, mouse, etc.).

      Hope this helps,

      Stephane

      1 Reply Last reply
      1
      • LaëtitiaL
        LaëtitiaL
        Laëtitia
        wrote on last edited by
        #3

        Hi Stephane,

        thanks for your answer, I'll do that then.

        Best

        Laëtitia

        1 Reply Last reply
        0

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Login or register to search.
        • First post
          Last post