错误:未定义对"MainWindow::on_Input_A_textChanged(QString const&)"的引用

error: undefined reference to `MainWindow::on_Input_A_textChanged(QString const&)'

本文关键字:const QString 引用 Input 未定义 MainWindow on 错误 textChanged      更新时间:2023-10-16

我遇到了一个奇怪的问题,我似乎无法理解。我是c++ Qt创建者的新手,我正在编写一个小计算器。但是我遇到了这个问题:

错误:未定义的引用' MainWindow::on_Input_A_textChanged(QString const&)

这是我的代码:

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QString"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}

void MainWindow::on_add_clicked()
{
double a,b,c;
a = ui->Input_A->text().toDouble();
b = ui->Input_B->text().toDouble();
c = a + b;
ui->Result->setText(QString::number(c));
}

我不使用函数的错误,所以我不知道什么是错的?我正在使用lineedit,它们被命名为:Input_A, Input_B, Result.

编辑:这是主窗口。h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_Input_A_textChanged(const QString &arg1);
void on_add_clicked();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H

直接删除(或实现)on_Input_A_textChanged:

class MainWindow : public QMainWindow
{
Q_OBJECT
public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
private slots:
    void on_add_clicked();
private:
    Ui::MainWindow *ui;
};

您可能删除了该方法,并且忘记了类中的声明。