Qt with OpenCV:LNK2019:未解析的外部符号和未找到文件mainwindow.obj

时间:2018-01-27 00:36:33

标签: qt opencv

我正在尝试构建由Computer-Vision-with-OpenCV-3-and-Qt5提供的示例qt-opencv项目Hello_Qt_OpenCV。我使用QtCreator4.5和Qt5.7以及opencv3.2。他们的配置与其他一些qt-opencv项目一起工作正常。

构建项目有三个问题:

File not found: mainwindow.obj: LNK2019: unresolved external symbol“void __cdecl cv :: medianBlur(class cv :: _ InputArray const&,class cv :: _ OutputArray const&,int)”(?medianBlur @ cv @@ YAXAEBV_InputArray @ 1 @ AEBV_OutputArray @ 1 @ H @ Z)在函数“private:void __cdecl MainWindow :: on_outputPushButton_pressed(void)”中引用(?on_outputPushButton_pressed @ MainWindow @@ AEAAXXZ)

File not found: mainwindow.obj: LNK2019: unresolved external symbol“void __cdecl cv :: GaussianBlur(class cv :: _ InputArray const&,class cv :: OutputArray const&,class cv :: Size ,double,double ,int)“(?GaussianBlur @ cv @@ YAXAEBV_InputArray @ 1 @ AEBV_OutputArray @ 1 @ V?$ Size_ @ H @ 1 @NNH @ Z)在函数”private:void __cdecl MainWindow :: on_outputPushButton_pressed(void)“中引用(? on_outputPushButton_pressed @ @@主窗口AEAAXXZ)

LNK1120: 2 unresolved externals release\Hello_Qt_OpenCV.exe:-1: error

我在(cleanrun qmakebuildFile not found: mainwindow.obj尝试了一些建议,但在这种情况下无效。

有关您的信息,我发布了mainwindow.cpp和mainwindow.h:

mainwindow.cpp:

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    loadSettings();
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_inputPushButton_pressed()
{
    QString fileName = QFileDialog::getOpenFileName(this, "Open Input Image", QDir::currentPath(), "Images (*.jpg *.png *.bmp)");
    if(QFile::exists(fileName))
    {
        ui->inputLineEdit->setText(fileName);
    }
}

void MainWindow::on_outputPushButton_pressed()
{
    QString fileName = QFileDialog::getSaveFileName(this, "Select Output Image", QDir::currentPath(), "*.jpg;;*.png;;*.bmp");
    if(!fileName.isEmpty())
    {
        ui->outputLineEdit->setText(fileName);
        using namespace cv;
        Mat inpImg, outImg;
        inpImg = imread(ui->inputLineEdit->text().toStdString());
        if(ui->medianBlurRadioButton->isChecked())
            cv::medianBlur(inpImg, outImg, 5);
        else if(ui->gaussianBlurRadioButton->isChecked())
            cv::GaussianBlur(inpImg, outImg, Size(5, 5), 1.25);
        imwrite(fileName.toStdString(), outImg);
        if(ui->displayImageCheckBox->isChecked())
            imshow("Output Image", outImg);
    }
}

void MainWindow::closeEvent(QCloseEvent *event)
{
    int result = QMessageBox::warning(this, "Exit", "Are you sure you want to close this program?", QMessageBox::Yes, QMessageBox::No);
    if(result == QMessageBox::Yes)
    {
        saveSettings();
        event->accept();
    }
    else
    {
        event->ignore();
    }
}

void MainWindow::loadSettings()
{
    QSettings settings("Packt", "Hello_OpenCV_Qt", this);
    ui->inputLineEdit->setText(settings.value("inputLineEdit", "").toString());
    ui->outputLineEdit->setText(settings.value("outputLineEdit", "").toString());
    ui->medianBlurRadioButton->setChecked(settings.value("medianBlurRadioButton", true).toBool());
    ui->gaussianBlurRadioButton->setChecked(settings.value("gaussianBlurRadioButton", false).toBool());
    ui->displayImageCheckBox->setChecked(settings.value("displayImageCheckBox", false).toBool());
}

void MainWindow::saveSettings()
{
    QSettings settings("Packt", "Hello_OpenCV_Qt", this);
    settings.setValue("inputLineEdit", ui->inputLineEdit->text());
    settings.setValue("outputLineEdit", ui->outputLineEdit->text());
    settings.setValue("medianBlurRadioButton", ui->medianBlurRadioButton->isChecked());
    settings.setValue("gaussianBlurRadioButton", ui->gaussianBlurRadioButton->isChecked());
    settings.setValue("displayImageCheckBox", ui->displayImageCheckBox->isChecked());
} 

mainwindow.h:

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QFileDialog>
#include <QDir>
#include <QFile>
#include <QCloseEvent>
#include <QMessageBox>
#include <QSettings>
#include "opencv2/opencv.hpp"

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

protected:
    void closeEvent(QCloseEvent *event);

private slots:
    void on_inputPushButton_pressed();

    void on_outputPushButton_pressed();

private:
    Ui::MainWindow *ui;

    void loadSettings();
    void saveSettings();

};

#endif // MAINWINDOW_H

您也可以下载项目文件并快速运行以查看问题是否与项目本身相关。

1 个答案:

答案 0 :(得分:0)

imgproc320文件中添加.pro,然后问题就解决了