You are not logged in.

1

Tuesday, July 23rd 2013, 7:05am

Unable to connect signal with slot

Hello Everyone,

This is my first post in this forum. I am newbie in C++ GUI development. I used qt 4.8 and create calculator. Below I am going to send you the source code of my basic calculator. My problem is, I am unable to connect slots with the given signals.

// CalculatorForm.cpp

#include <iostream>
#include "CalculatorForm.h"

CalculatorForm::CalculatorForm() {
widget.setupUi(this);

ui_FirstOperand = findChild<QDoubleSpinBox*>("FirstOperand");
ui_SecOperand = findChild<QDoubleSpinBox*>("SecOperand");
ui_RstBox = findChild<QLineEdit*>("RstBox");

// Connect the Signals with slots...
connect(widget.AddOperator, SIGNAL(clicked()), this,
SLOT(this->On_AddOperator_Selection()));

connect(widget.SubOperator, SIGNAL(clicked()), this,
SLOT(this->On_SubOperator_Selection()));

connect(widget.MultiOperation, SIGNAL(clicked()), this,
SLOT(this->On_MultiOperator_Selection()));
}


// CalculatorForm.h
#include "ui_CalculatorForm.h"



class CalculatorForm : public QDialog {
Q_OBJECT

public:
CalculatorForm();
virtual ~CalculatorForm();

private slots:
void On_AddOperator_Selection();
void On_SubOperator_Selection();
void On_MultiOperator_Selection();

private:
Ui::CalculatorForm widget;
QDoubleSpinBox *ui_FirstOperand;
QDoubleSpinBox *ui_SecOperand;
QLineEdit *ui_RstBox;
};


CalculatorForm::~CalculatorForm() {
}



void CalculatorForm :: On_AddOperator_Selection() {

// Add the values and assign it into double variable.
double dRst = ui_FirstOperand->value() + ui_SecOperand->value();

// Convert the double into string.
QString valueAsString = QString::number(dRst);

// Set the value in the resultant box.
ui_RstBox->setText(valueAsString);
}



void CalculatorForm :: On_SubOperator_Selection() {

// Subtract the values and assign it into double variable.
double dRst = ui_FirstOperand->value() - ui_SecOperand->value();

// Convert the double into string.
QString valueAsString = QString::number(dRst);

// Set the value in the resultant box.
ui_RstBox->setText(valueAsString);
}



void CalculatorForm :: On_MultiOperator_Selection() {

// Multiply the values and assign it into double variable.
double dRst = ui_FirstOperand->value() * ui_SecOperand->value();

// Convert the double into string.
QString valueAsString = QString::number(dRst);

// Set the value in the resultant box.
ui_RstBox->setText(valueAsString);
}



// Main.cpp

#include <QtGui/QApplication>
#include "CalculatorForm.h"

int main(int argc, char *argv[]) {
// initialize resources, if needed
// Q_INIT_RESOURCE(resfile);
QApplication app(argc, argv);

// Initialize the class variable of CalculatorForm
CalculatorForm form;

// Show the form at run time.
form.show();

// create and show your widgets here

return app.exec();
}

Please find the GUI attached along with this mail.

If there is any mistake in my code then please tell me as I am newbie with the qt may be I made a blunder mistake so please tell me like child so that I will understand. In the given GUI you will get 2 QDoubleSpinBox, 1 Textbox, 3 radio button. I want to manipulate the value contain by the QDoubleSpinBox through radiobutton and show the result in the text box. But I am unable to do that.

Thanks and Regard,
Antrikssh... :)
Antrikssh has attached the following file:
  • Calculator.png (15.37 kB - 3 times downloaded - latest: Aug 10th 2013, 2:14am)

This post has been edited 1 times, last edit by "Antrikssh" (Jul 23rd 2013, 7:11am)


_Blueman

Intermediate

  • "_Blueman" celebrates his birthday today
  • "_Blueman" is male

Posts: 196

Location: Poland

  • Send private message

2

Tuesday, July 23rd 2013, 8:20am

check this tutorial for beginners

3

Thursday, July 25th 2013, 1:08am

I assume the connect you mean is the one for the add and subtract operator? I don't see anything obvious but I can suggest some things I would check:

Check the type of widget you're connecting from and the signals it emits. Not all widgets emit the clicked signal.

Check to see if there are parameters on the signal and the slot. Your connect call should include the parameters.

Check the slots are really in the class you refer to in the connect call. (Try making your slots public instead of private and see if that helps)

4

Thursday, July 25th 2013, 6:21am

Hello Everyone,

Thanks for giving your time for my problem. I will accept both the suggestion and go through with that.Especially with the pdf that provided by the _Blueman that will strong my basic of qt programming. jsprenkle your suggestion will also helpful me. So thanks both of you. If I will find any difficulty, I will post that.

Thanks and Regard,
Antrikssh....

5

Monday, July 29th 2013, 2:48pm

Hello Everyone,

The above pdf is really good. Thanks for giving me such support. If you have some more suggestion regarding to book and related document links please provide to the beginner like me. I want to learn more about GUI development in C++.

Thanks and Regard
Antrikssh........