也许这个错误正在调用,因为我的错误包含语句... 错误消息:
mainwindow.obj:-1: error: LNK2019: unresolved external symbol "public: __thiscall MatrixGetter::MatrixGetter(void)" (??0MatrixGetter@@QAE@XZ) referenced in function "private: void __thiscall MainWindow::on_pushButton_clicked(void)" (?on_pushButton_clicked@MainWindow@@AAEXXZ)
mainwindow.obj:-1: error: LNK2019: unresolved external symbol "public: void __thiscall MatrixGetter::getCountries(void)" (?getCountries@MatrixGetter@@QAEXXZ) referenced in function "private: void __thiscall MainWindow::on_pushButton_clicked(void)" (?on_pushButton_clicked@MainWindow@@AAEXXZ)
debug\MdpProject.exe:-1: error: LNK1120: 2 unresolved externals
MdpProject.pro文件
######################################################################
# Automatically generated by qmake (3.0) ?? ??? 27 01:48:55 2014
######################################################################
TEMPLATE = app
TARGET = MdpProject
INCLUDEPATH += .
QT += sql
# Input
HEADERS += dialog.h mainwindow.h matrixgetter.h matrixgetterdao.h
FORMS += dialog.ui mainwindow.ui
SOURCES += dialog.cpp \
main.cpp \
mainwindow.cpp \
matrixgetter.cpp \
matrixgetterdao.cpp
MainWindow.h课程:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "matrixgetter.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_pushButton_clicked();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
MainWindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "dialog.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->progressBar->setValue(100);
}
QString prop;
QString country;
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
Dialog *d = new Dialog();
// MatrixGetter* mgetter = new MatrixGetter();
// mgetter->getCountries();
d -> show();
}
如果我取消注释这些行,一切都会好的。 MatrixGetter有一个空方法getCountries():
MatrixGetter.h
#ifndef MATRIXGETTER_H
#define MATRIXGETTER_H
namespace Ui {
class MatrixGetter;
}
class MatrixGetter
{
public:
MatrixGetter();
void getCountries();
};
#endif // MATRIXGETTER_H
MatrixGetter.cpp
#include "matrixgetter.h"
MatrixGetter::MatrixGetter()
{}
void MatrixGetter::getCountries(){}