c++ - 错误 : undefined reference to `MainWindow::on_Input_A_textChanged(QString const&)'

标签 c++ qt qt-creator

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

错误:对`MainWindow::on_Input_A_textChanged(QString const&) 的 undefined reference

这是我的代码:

#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));
}

我没有使用出错误的功能所以我不知道哪里出了问题? 我正在使用 lineEdits,它们被命名为:Input_A、Input_B、Result。

编辑: 这是mainwindow.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;
};

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

关于c++ - 错误 : undefined reference to `MainWindow::on_Input_A_textChanged(QString const&)' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32466377/

相关文章:

c++ - 在c中的多级双向链表中添加一个节点

c++ - QTcpClient 成功连接,但没有连接到我的服务器。它连接在哪里?

c++ - 找不到“ui_mainwindow.h”文件

c++ - 如何浏览嵌套的 for 循环

c++ - Qt Creator - 如何启用 float IDE 布局?

mysql - Qt creator 中的连接数据库

linux - 使用 Qt Creator 和 Linux boost

c++ - 停止在 odeint 中对僵硬 ode 进行积分

c++ - 交换单个链表上的节点

c++ - 在不减慢线程速度的情况下保存大量数据