【问题标题】:QT Creator Linking Error 1120QT Creator 链接错误 1120
【发布时间】:2013-11-16 20:25:46
【问题描述】:

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

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

【问题讨论】:

  • 您为 on_cboxMode_activated 声明了两个重载(一个采用 int,一个采用 const QString& 作为参数),但只定义了 (int) 一个。

标签: c++ qt linker


【解决方案1】:

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

【讨论】:

  • 我在帖子中添加了头文件
  • 你有两个 on_cboxMode_activated (并且一个接受 QString& 的那个没有在 .cpp 文件中定义)是你想要的吗?如果是这样,您必须为采用 QString& 参数的方法编写一个实现。
  • 我不是想把它放在那里,删除它解决了这个问题。谢谢。
猜你喜欢
  • 1970-01-01
  • 2014-03-15
  • 2015-09-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-12
相关资源
最近更新 更多