QT 创建器链接错误 1120

QT Creator Linking Error 1120

本文关键字:错误 1120 链接 创建 QT      更新时间:2023-10-16

我一直在尝试在Qt Creator中编译我的项目。我已经多次运行 qmake 和清理,但仍然遇到链接错误。

moc_test.obj:-1: error: LNK2019: unresolved external symbol "private: void __cdecl Test::on_cboxMode_activated(class QString const &)" (?on_cboxMode_activated@Test@@AEAAXAEBVQString@@@Z) referenced in function "private: static void __cdecl Test::qt_static_metacall(class QObject *,enum QMetaObject::Call,int,void * *)" (?qt_static_metacall`enter code here`@Test@@CAXPEAVQObject@@W4Call@QMetaObject@@HPEAPEAX@Z)

这是项目文件

#-------------------------------------------------
#
# Project created by QtCreator 2013-10-25T13:51:21
#
#-------------------------------------------------
QT       += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Test
TEMPLATE = app

SOURCES += test.cpp
            main.cpp

HEADERS  += test.h
FORMS    += test.ui

这是我的cpp文件

#include "test.h"
#include "ui_test.h"
#include <QFileDialog>
Test::Test(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::Test)
{
    ui->setupUi(this);
}
Test::~Test()
{
    delete ui;
}
//********************************//
//**Browse and Select A Fit File**//
//********************************//
void Test::on_btnFitBrowse_clicked()
{
    QString fileName = QFileDialog::getOpenFileName(this,tr("Open File"), "/home/", tr("Comma Delimited (*.csv);;Text Files (*.txt);;All Files(*)"));
    ui->txtFitEdit->setText(fileName);
}
//*********************************//
//**Browse and Select A Test File**//
//*********************************//
void Test::on_btnTestBrowse_clicked()
{
    QString fileName = QFileDialog::getOpenFileName(this,tr("Open File"), "/home/", tr("Comma Delimited (*.csv);;Text Files (*.txt);;All Files(*)"));
    ui->txtTestEdit->setText(fileName);
}
//--------------------------------------------------------------------//
//----------------------------Model Window----------------------------//
//--------------------------------------------------------------------//
//***************//
//**Select Mode**//
//***************//
void Test::on_cboxMode_activated(int index)
{
    //Auto Mode
    if(index==0)
    {
        ui->rdoBestTMinMSE->setEnabled(false);
        ui->rdoBestTMaxF->setEnabled(false);
    }
    //Manual Mode
    else if(index==1)
    {
        ui->rdoBestTMinMSE->setEnabled(true);
        ui->rdoBestTMaxF->setEnabled(true);
    }
}

这是我的头文件

#ifndef TEST_H
#define TEST_H
#include <QMainWindow>
#include <QRadioButton>
namespace Ui {
class Test;
}
class Test : public QMainWindow
{
    Q_OBJECT
public:
    explicit Test(QWidget *parent = 0);
    ~Test();
private slots:
    void on_btnFitBrowse_clicked();
    void on_btnTestBrowse_clicked();
    void on_cboxMode_activated(const QString &arg1);
    void on_cboxMode_activated(int index);
private:
    Ui::Test *ui;
};
#endif // TEST_H

我的目录结构如下所示

+---Test Qt
¦   +---build-Test-Desktop_Qt_5_1_1_MSVC2012_OpenGL_64bit-Debug
¦   ¦   +---debug
¦   ¦   +---release
¦   +---build-Test-Desktop_Qt_5_1_1_MSVC2012_OpenGL_64bit-Release
¦   ¦   +---debug
¦   ¦   +---release
¦   +---Test

很可能你有一个 Test::on_cboxMode_activated 将 QString& 带入 test.h 和 测试中.cpp你有带有 int 参数的方法。 如果不是这种情况,请也从test.h发布代码