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. Use changed spinbox-value in another void-function
Forum Updated to NodeBB v4.3 + New Features

Use changed spinbox-value in another void-function

Scheduled Pinned Locked Moved General and Desktop
11 Posts 3 Posters 4.2k 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.
  • V Offline
    V Offline
    vcsala
    wrote on last edited by
    #2

    I beleive you wanted to write the following (the assigment was wrong in your original):

    @void Tab::setVal(int value) {
    k = value;
    }@

    And the parameter type of setVal is missing in your connect call.

    1 Reply Last reply
    0
    • N Offline
      N Offline
      newe1
      wrote on last edited by
      #3

      Thanks so far.

      I changed:
      @
      void Tab::setVal(int value)
      {
      k = value;
      }
      @

      and:
      @
      ....
      connect(intSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setVal(int)));
      }
      @

      but the "void Tab::calculate()" function still does not get the value of "k"...

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

        Additionally, your connect statement is wrong. This is the correct version:

        @
        connect(intSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setVal(int)));
        @

        Spot the int parameter in SLOT (setVal(int)).

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

        1 Reply Last reply
        0
        • V Offline
          V Offline
          vcsala
          wrote on last edited by
          #5

          [quote author="newe1" date="1305371816"]but the "void Tab::calculate()" function still does not get the value of "k"... [/quote]

          What does happen? Does it raise division by zero exception? Have you tried to debug it and check if the setVal function is called? And check what is the value of k in the calculate function?

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

            Nothing bad happens. The connect just fails (connect returns false) and Qt prints a warning to the console indicating that there is no slot with that signature (setVal without parameters). Just try and watch :)

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

            1 Reply Last reply
            0
            • N Offline
              N Offline
              newe1
              wrote on last edited by
              #7

              Hi again!

              Thanks Volker, I changed it. We were posting at the same time :-)

              VCsala: Well it happens nothing. The divison by zero exception is not made, because of my range 2 to 20.

              This are the private Slots:
              @
              private slots:
              void calculate();
              void setVal(int);
              @

              I´m using "k" like this:
              @
              void Tab::calculate()
              {
              double result, result1, result2, a, ....;

              if(radio1->isChecked())
              {
                 result = a/k;
              }
              if(k==2)
              {
                 if(radio2->isChecked())
                  {
                      result = a/k;               //1. 
                      result1 = a/k*2;          //2.
                      QString result1String = "";
                      re1->setText(result1String.setNum(result));
                      QString result2String = "";
                      re2->setText(result2String.setNum(result1));
                  }
                  else
                  {
                     QString result1String = "";
                     re1->setText(result1String.setNum(result));
                     re2->setText(result1String.setNum(result));
                  }
               if(k==3)
                   if(radio2->isChecked())
                  {
                      result = a/k;         //1.
                      result1 = a/k*2;    //2.
                      result2 = a/k*3;    //3.
              

              .....
              @

              When I debug, I don´t get any error... but it does not get "k"...

              VCsala: How do I check if the setval function is called?

              Thanks in advance!

              1 Reply Last reply
              0
              • V Offline
                V Offline
                vcsala
                wrote on last edited by
                #8

                Just set a breakpoint in the function, run the app in debugger and see if it stops there or not.

                What does happen if you declare the slot to public?

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  goetz
                  wrote on last edited by
                  #9

                  From where is your calculate function called?

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

                  1 Reply Last reply
                  0
                  • N Offline
                    N Offline
                    newe1
                    wrote on last edited by
                    #10

                    Hi!

                    Thank you VCsala and Volker for your ideas. It took me quite some time to solve the problem but now everything runs fine.

                    Finally I rebuilt everything without the GroupBox and it got the value of "k". I´m not 100% sure, why it could not get it before (maybe because of other interferring problems) but now it works. :-)

                    But I didn´t declare the slots to public. Just private slots, with the code above and it gets the value of "k".

                    Thanks anyway!

                    1 Reply Last reply
                    0
                    • V Offline
                      V Offline
                      vcsala
                      wrote on last edited by
                      #11

                      Your welcome. I am glad that you solved the problem finally!

                      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