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. signal interval question
Forum Updated to NodeBB v4.3 + New Features

signal interval question

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 371 Views
  • 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.
  • C Offline
    C Offline
    clementNg
    wrote on last edited by
    #1

    I want to change my signal to change value in an interval.
    For example, I want to update the valueSpinBox when i have changed the horizontalSliders.

    connect(horizontalSliders, &SlidersGroup::valueChanged, [=](int value){
       this->ui->valueSpinBox->setValue(value);
    });
    

    However, I want to change the value in an interval 200ms intead of changing them real time. Is it possible? Thank you.

    jsulmJ 1 Reply Last reply
    0
    • C clementNg

      I want to change my signal to change value in an interval.
      For example, I want to update the valueSpinBox when i have changed the horizontalSliders.

      connect(horizontalSliders, &SlidersGroup::valueChanged, [=](int value){
         this->ui->valueSpinBox->setValue(value);
      });
      

      However, I want to change the value in an interval 200ms intead of changing them real time. Is it possible? Thank you.

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

      @clementNg You will need to use QTimer
      For example, if you want to do the actual change 200ms after signal was emitted you can use https://doc.qt.io/qt-5/qtimer.html#singleShot

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

      C 1 Reply Last reply
      3
      • jsulmJ jsulm

        @clementNg You will need to use QTimer
        For example, if you want to do the actual change 200ms after signal was emitted you can use https://doc.qt.io/qt-5/qtimer.html#singleShot

        C Offline
        C Offline
        clementNg
        wrote on last edited by clementNg
        #3

        @jsulm
        Thank you for your reply. Do I need to disconnect the signal and connect again after the interval? Would you mind to give a simple example? Thanks.

        QTimer::singleShot(200, [=](){
        // connect my horizontalSliders slot here?
        // disconnect the slot after the action?
        });
        
        jsulmJ 1 Reply Last reply
        0
        • C clementNg

          @jsulm
          Thank you for your reply. Do I need to disconnect the signal and connect again after the interval? Would you mind to give a simple example? Thanks.

          QTimer::singleShot(200, [=](){
          // connect my horizontalSliders slot here?
          // disconnect the slot after the action?
          });
          
          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @clementNg

          connect(horizontalSliders, &SlidersGroup::valueChanged, [=](int value){
              QTimer::singleShot(200, [=](){
                  this->ui->valueSpinBox->setValue(value);
              });
          });
          

          No need to disconnect as singleShot does not connect anything.

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

          1 Reply Last reply
          3

          • Login

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