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. [SOLVED] Signals and Slots beginner problem

[SOLVED] Signals and Slots beginner problem

Scheduled Pinned Locked Moved General and Desktop
20 Posts 6 Posters 6.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.
  • D Offline
    D Offline
    Dn588
    wrote on last edited by
    #10

    Thanks ScotR and IamSumit I won't forget that in future:)

    My calculate_clicked slot now looks like this:

    @
    {
    bmi obj;
    weight = m_weight->value();
    height = m_height->value();
    retVal = obj.calcBmi(weight, height);
    bmi.setText(bmiVal);
    }
    @

    Now i'm getting an error "No matching function bmi::bmi() candidates are bmi::bmi(double double) and bmi::bmi(const bmi&)
    but when I instantiate bmiObj I pass weight and height as parameters which are both of type double.
    Any idea what I am doing wrong?

    [edit: added coding tags SGaist]

    1 Reply Last reply
    0
    • S Offline
      S Offline
      ScottR
      wrote on last edited by
      #11

      [quote author="Dn588" date="1396455117"]

      Any idea what I am doing wrong?[/quote]

      1. You are forgetting to put your code inside of "@" signs.

      2. I don't know what the line
        @
        bmi obj;
        @

      does. You haven't shown the definition of the type "bmi".

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Dn588
        wrote on last edited by
        #12

        Hi ScottR Sorry I completely forgot about code formatting...

        My bmi class looks like this:

        @

        bmi.h

        #ifndef BMI_H
        #define BMI_H

        class bmi
        {
        public:
        bmi(double weight, double height);
        double calcBmi(double weight, double height);
        private:
        double m_weight, m_height;
        };

        #endif // BMI_H

        bmi.cpp

        #include "bmi.h"

        bmi::bmi(double weight, double height) : m_weight(weight), m_height(height)
        {

        }

        double bmi::calcBmi(doubleweight, double height) {
        return weight / (height * height);
        }
        @

        1 Reply Last reply
        0
        • S Offline
          S Offline
          ScottR
          wrote on last edited by
          #13

          You want to use
          @
          bmi obj(weight, height);
          @

          I can't tell where you will get weight and height from.

          I think you may be confused between the bmiGui class and the bmi class?

          1 Reply Last reply
          0
          • IamSumitI Offline
            IamSumitI Offline
            IamSumit
            wrote on last edited by
            #14

            You have two choice either pass the values in constructor or in function(as i gave you code)
            [quote author="Dn588" date="1396468975"]Hi ScottR Sorry I completely forgot about code formatting...

            My bmi class looks like this:

            @

            bmi.h

            #ifndef BMI_H
            #define BMI_H

            class bmi
            {
            public:
            bmi(double weight, double height);
            double calcBmi(double weight, double height);
            private:
            double m_weight, m_height;
            };

            #endif // BMI_H

            bmi.cpp

            #include "bmi.h"

            bmi::bmi(double weight, double height) : m_weight(weight), m_height(height)
            {

            }

            double bmi::calcBmi(doubleweight, double height) {
            return weight / (height * height);
            }
            @[/quote]

            Here you should use a simple constructor without parameter.
            e.g;
            instead of
            bmi(double weight, double height); write bmi(); only
            edit your code in both .h and .cpp file for simple parameterless constructor.

            hope it helps

            Be Cute

            1 Reply Last reply
            0
            • D Offline
              D Offline
              Dn588
              wrote on last edited by
              #15

              Thanks That worked:) Now i'm getting a few error messages saying undefined reference to 'vtable for bmiGui' any idea what that means?

              1 Reply Last reply
              0
              • JohanSoloJ Offline
                JohanSoloJ Offline
                JohanSolo
                wrote on last edited by
                #16

                This most probably means that your moc file is not up to date. Try to clean the project, run qmake and build again.

                And be sure that your classes using signal and slots have the Q_OBJECT macro (before running qmake).

                Edit: it may also be caused by a forgotten dependance in your .pro file. Could you give a more detailed compiler output?

                `They did not know it was impossible, so they did it.'
                -- Mark Twain

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  Dn588
                  wrote on last edited by
                  #17

                  Thanks a lot it's working Perfectly now!.

                  One more thing i'm struggling to find,
                  when creating a layout is there any member function of QRadioButton to set a radioButton as checked by default when the program starts?

                  1 Reply Last reply
                  0
                  • IamSumitI Offline
                    IamSumitI Offline
                    IamSumit
                    wrote on last edited by
                    #18

                    HI ..
                    Yes .Use
                    void setChecked(bool)
                    member function.
                    Hope it helps

                    Be Cute

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      Dn588
                      wrote on last edited by
                      #19

                      Thanks IamSumit that worked:)

                      1 Reply Last reply
                      0
                      • EddyE Offline
                        EddyE Offline
                        Eddy
                        wrote on last edited by
                        #20

                        Hi,
                        Could you please edit your first post and prepend [solved] to it. That way others can see easily it's solved. Thanks.

                        Qt Certified Specialist
                        www.edalsolutions.be

                        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