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. Is there any way of knowing the current value repeatedly when a valuechanged() signal is emitted by slider?
Forum Updated to NodeBB v4.3 + New Features

Is there any way of knowing the current value repeatedly when a valuechanged() signal is emitted by slider?

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 3.3k 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.
  • P Offline
    P Offline
    pratik041
    wrote on last edited by
    #1

    while i am implementing
    @QObject::connect(mb, SIGNAL(valuechanged(int)),.............);@
    In this case how can i know what is the value at each time.I want this because at particular value i want to call a function.

    Pratik Agrawal

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

      Create a slot that takes an integer value. In that slot, check if the received number matches the number you're looking for, call the function you want to call. Connect the valueChanged signal to your slot.

      Keep in mind that you might not receive the number you are looking for. valueChanged() doesn't get called at every number.

      "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
      • P Offline
        P Offline
        pratik041
        wrote on last edited by
        #3

        Ok thank's i was also trying in the same way but Is there any other way to do this ?

        Pratik Agrawal

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

          What do you want to achieve? That is, why do you want to call that function when the slider hits a specific number?

          "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
          • P Offline
            P Offline
            pratik041
            wrote on last edited by
            #5

            actually near the slider i have a speaker image. I want to change speaker image according to slider handle position. Speaker image can be changed by calling set_image(int image_index) slot. So for that at particular position of slider handle position i have to call set_image slot.
            The problem here is that the set_image slot is already written and i can't edit it.

            Pratik Agrawal

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

              Right. It is wise to check the ranges, rather than the bordering values.

              Let's assume the set_image() function doesn't update unless it has to, else get the current index and compare. Assume range is 0-100 and there are four images.

              @
              void Thingy::updateIconForValueBluntly(int v)
              {
              set_image(v/25);
              }

              void Thingy::updateIconForValueSmartly(int v)
              {
              if (v < 10)
              set_image(0);
              else if (v < 30)
              set_image(1);
              else if (v < 65)
              set_image(2);
              else
              set_image(3);
              }

              void Thingy::updateIconForValueSomewhatPythonically(int v)
              {
              static const QVector vec = QVector() << 10 << 30 << 65 << 100;

              for (int i = 0; i < vec.size(); ++i) {
                  if (v < vec.at(i)) {
                      set_image(i);
                      return;
                  }
              }
              set_image(vec.count() - 1);
              

              }
              @

              Probably goes without saying, all code is untested.

              "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
              • P Offline
                P Offline
                pratik041
                wrote on last edited by
                #7

                ok thank you

                Pratik Agrawal

                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