Student_Help
-
Hello and good day,
I am trying to figure out how initiate the calculations
as well as bring up the message box based on the
Pushbutton Calculate being pressed ??
Please help.#include <QApplication>
#include <QVBoxLayout>
#include <QSpinBox>
#include <QLabel>
#include <QtGui>
#include <QWidget>
#include <QPushbutton>
#include <QSlider>
#include <QMessageBox>int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget window;QVBoxLayout* mainLayout = new QVBoxLayout(&window);
window.setWindowTitle("Exam Mark Calculator");
QLabel* Label1 = new QLabel("Assignment 1");
QSpinBox* SpinBox1 = new QSpinBox;
QLabel* Label2 = new QLabel("Assignment 2");
QSpinBox* SpinBox2 = new QSpinBox;
QLabel* Label3 = new QLabel("Assignment 3");
QSpinBox* SpinBox3 = new QSpinBox;
QMessageBox* MessageBox1 = new QMessageBox;QLabel* Year_Mark = new QLabel("Year Mark Percentage:");
QLabel* Exam_Mark = new QLabel("Year Mark Percentage:");
QLabel* Label4 = new QLabel("YearMark");
QLabel* Notes_LabelHead = new QLabel("Notes:");
QLabel* Notes_Label1 = new QLabel("Assignment 1( Weight = 20%)");
QLabel* Notes_Label2 = new QLabel("Assignment 2( Weight = 50%)");
QLabel* Notes_Label3 = new QLabel("Assignment 3( Weight = 30%)");
QLabel* Notes_Label4 = new QLabel("Assignment 1+2+3 = Year Mark");
QLabel* Notes_Label5 = new QLabel("Year Mark = 20% of Final Mark");
QLabel* Notes_Label6 = new QLabel("Exam Mark = 80% of Final Mark");
QLabel* Notes_Label7 = new QLabel("Pass Mark = 50%");
QPushButton* Calculate = new QPushButton ("Calculate");
QSlider* Slider1 = new QSlider;SpinBox1->setMaximum(100);
SpinBox2->setMaximum(100);
SpinBox3->setMaximum(100);mainLayout->addWidget(Label1);
mainLayout->addWidget(SpinBox1);
mainLayout->addWidget(Label2);
mainLayout->addWidget(SpinBox2);
mainLayout->addWidget(Label3);
mainLayout->addWidget(SpinBox3);
mainLayout->addWidget(Year_Mark);
mainLayout->addWidget(Label4);
mainLayout->addWidget(Notes_LabelHead);
mainLayout->addWidget(Notes_Label1);
mainLayout->addWidget(Notes_Label2);
mainLayout->addWidget(Notes_Label3);
mainLayout->addWidget(Notes_Label4);
mainLayout->addWidget(Notes_Label5);
mainLayout->addWidget(Notes_Label6);
mainLayout->addWidget(Notes_Label7);
mainLayout->addWidget(Calculate);
//mainLayout->addWidget(MessageBox1);double Ass1Percent;
double Ass2Percent;
double Ass3Percent;
double YearMark;
double ExamMark;//*****!!!!if Calculate->pressed(); then do
{
Ass1Percent = SpinBox1->value()0.022;
Ass2Percent = SpinBox2->value()0.052;
Ass3Percent = SpinBox3->value()0.032;
YearMark = Ass1Percent + Ass2Percent + Ass3Percent;
Label4->setText(QString::number(YearMark)+' %');
ExamMark = 100 - YearMark;
MessageBox1->show();
MessageBox1->setText("Exam Mark Percentage: "+QString::number(ExamMark)+' %');
}window.show();
return a.exec();
} -
You have to create a derivate class from QWidget, declare a slot method that do calculation and connect it to the signal "clicked" of the QPushButton.
If you are a student, so it wouldn't a problem for you to read carefully the documentation of Qt regarding signal/slot mechanism:
http://qt-project.org/doc/qt-5/signalsandslots.html
http://qt-project.org/doc/qt-5/gettingstartedqt.html -
Thank You Kindly Gianluca, i will work on it this weekend.