[英]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. 我正在尝试制作一个简单的程序来计算2个数字并在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. 因此,基本上,我在第一个textedit中的值更改时建立连接,该连接将进入bereken函数,该函数将获取textedits的2个值并进行计算。
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));
}
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*. SLOT宏返回const char *。
Seems like SIGNAL return void, so the line 好像SIGNAL返回void,所以这行
QObject::connect(number1, SIGNAL(textChanged(QString)),this,bereken());
is wrong use of this function. 使用此功能是错误的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.