user1633254
user1633254

Reputation:

Cannot convert parameter 4 from 'void' to 'const char *'

I'm trying to make a simple program to calculate 2 numbers and give the sum on a label in Qt. But I got an error and I don't know what I did wrong.

I got this error:

K:\QtSDK\QT_files\les4-build-desktop-Qt_4_8_1_for_Desktop_-  _MSVC2010__Qt_SDK__Debug\..\les4\calcu.cpp:40: error: C2664: 'bool QObject::connect(const     QObject *,const char *,const QObject *,const char *,Qt::ConnectionType)' : cannot convert     parameter 4 from 'void' to 'const char *'
Expressions of type void cannot be converted to other types

So basicly I make a connect when the value change in the first textedit it will go to the bereken function, that will get the 2 values of the textedits and will calculate them.

Calcu.h

#ifndef CALCU_H
#define CALCU_H

#include <QWidget>
#include <QLineEdit>
#include <QLabel>

namespace Ui {
class calcu;
}

class calcu : public QWidget
{
Q_OBJECT

public:
explicit calcu(QWidget *parent = 0);
~calcu();
 public slots:
void bereken(void);


private:
Ui::calcu *ui;
QLineEdit *number1 ;
QLineEdit *number2 ;
QLabel *sum;
};

#endif // CALCU_H

calcu.ccp

#include "calcu.h"
#include "ui_calcu.h"
#include <QLineEdit>
#include <QLabel>
#include <QHBoxLayout>
#include <QMessageBox>
#include <QString>

calcu::calcu(QWidget *parent) :
QWidget(parent),
ui(new Ui::calcu)
{
ui->setupUi(this);

QGridLayout *grid = new QGridLayout;

number1 = new QLineEdit;
number2 = new QLineEdit;
QLabel *sign = new QLabel("+");
QLabel *equal = new QLabel("=");
sum = new QLabel;

QHBoxLayout *layout = new QHBoxLayout;

layout->addWidget(number1);
layout->addWidget(sign);
layout->addWidget(number2);
layout->addWidget(equal);
layout->addWidget(sum);

   // this->setLayout(layout);
ui->groupBox->setLayout(layout);
ui->groupBox->setTitle("Enter som");

setWindowTitle(tr("Group Boxes"));
   // resize(480, 320);

setLayout(grid);

QObject::connect(number1, SIGNAL(textChanged(QString)),this,bereken());

   // bereken();

}

calcu::~calcu()
{
delete ui;
}

void calcu::bereken(){

int som;
QString number;
number = number1->text();
som = number.toInt();

number = number2->text();
som = som + number.toInt();


sum->setText(QString::number(som));
}

Upvotes: 0

Views: 1693

Answers (2)

Luca Carlon
Luca Carlon

Reputation: 9986

I suppose you wanted the line:

QObject::connect(number1, SIGNAL(textChanged(QString)),this,bereken());

to be:

QObject::connect(number1, SIGNAL(textChanged(QString)),this, SLOT(bereken()));

The SLOT macro returns the const char*.

Upvotes: 3

LeeNeverGup
LeeNeverGup

Reputation: 1114

Seems like SIGNAL return void, so the line

QObject::connect(number1, SIGNAL(textChanged(QString)),this,bereken());

is wrong use of this function.

Upvotes: 0

Related Questions