Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7944003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:26:02+00:00 2026-06-04T00:26:02+00:00

This is a program that calculates the BMI by inputting weight and height #ifndef

  • 0

This is a program that calculates the BMI by inputting weight and height

#ifndef BMIVIEWER_H
#define BMIVIEWER_H
#include <QWidget>
#include <QGridLayout>
#include <QLineEdit>
#include <QLabel>
#include <QPushButton>
#include <QLCDNumber>
#include <QErrorMessage>
#include <QString>
#include <QMessageBox>

class BmiViewer : public QWidget {
   Q_OBJECT

public:

    BmiViewer();
    void calculateBmi();

private:
 QLineEdit* heightEntry;
 QLineEdit* weightEntry;
 QLCDNumber* result;
 QErrorMessage* error;
};

#endif // BMIVIEWER_H

bmiviewer.cpp

#include "bmiviewer.h"
BmiViewer::BmiViewer(){
setWindowTitle("MMI Calculator");
QGridLayout* layout = new QGridLayout;
QLabel* inputWeightRequest = new QLabel ("Enter weight in Kg:");
weightEntry = new QLineEdit;
QLabel* inputHeightRequest = new QLabel ("Enter height in meters:");
heightEntry = new QLineEdit;
QPushButton* calc = new QPushButton ("Calculate");
QLabel* labelbmi = new QLabel ("BMI");
result = new QLCDNumber;

result->setSegmentStyle(QLCDNumber::Flat);
result->setDigitCount(8);

layout->addWidget (inputWeightRequest, 0,0);
layout->addWidget (weightEntry, 0,1);
layout->addWidget (inputHeightRequest, 1,0);
layout->addWidget (heightEntry, 1,1);
layout->addWidget (calc, 2,1);
layout->addWidget (labelbmi, 3,0);
layout->addWidget (result, 3,1);

setLayout(layout);

//connect signals and slots

connect(calc,SIGNAL(clicked()),this, SLOT(calculateBmi()));

}

void BmiViewer::calculateBmi(){
int wanswer=0;
int hanswer=0;
double bmi;
QString iStr = weightEntry->text();
QString iStrh = heightEntry->text();
bool ok;
wanswer = iStr.toInt(&ok);
hanswer = iStrh.toInt(&ok);
if (!ok) {
 error = new QErrorMessage(this);
 error->showMessage("Please enter a valid integer");
 return;
}


    //calculate BMI

    bmi=wanswer/(hanswer*hanswer);
    result->display(bmi);

   }

main.cpp

#include <QApplication>
#include "bmiviewer.h"

int main(int argc, char *argv[]) {
    QApplication a(argc, argv);
    BmiViewer w;
    w.show();

    return a.exec();
}

When I compile it it outputs: Object::connect: No such slot BmiViewer::calculateBmi() in bmiviewer.cpp:29

It displays the interface but no calculations are done.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T00:26:04+00:00Added an answer on June 4, 2026 at 12:26 am

    Add the line

    public slots:
    

    before

    void calculateBmi();
    

    You never declared the bmi function a slot and so it can’t be connected to.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some trouble returning multiple values in this program that calculates min, max,
/*This is a program that calculates Internet advertising rates based on what features/options you
I have this java program which calculates the time that the person took to
Write a program that calculates Euler’s number e. To do this, first write a
I am writing a program in C that calculates this formula: (source: crewtonramoneshouseofmath.com )
I have this program that should execute a piece of code base on the
I bought this program that created a pretty nice imageuploader flash script however I
I have this program that I am working on for class, I think the
Below is the program that I wrote. /******************************************************************************* * This program reads EOF from
I have a C/ncurses program that I'm debugging/maintaining. This program does ripoffline twice: first,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.