我一直在尝试在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
答案 0 :(得分:0)
很可能你有一个Test :: on_cboxMode_activated,它将 QString&amp; 带入 test.h 和 test.cpp 你使用 int 参数的方法。 //如果不是这样,请发布 test.h 的代码