我有一个正常工作的Qt代码与自定义小部件。然后我折射了一个信号名称并立即撤消操作。从那时起我就到了 -
mainwindow.obj:-1: error: LNK2001: unresolved external symbol "protected: virtual void
__thiscall QWidget::mouseDoubleClicked(class QMouseEvent *)"
?mouseDoubleClicked@QWidget@@MAEXPAVQMouseEvent@@@Z)
mouseDoubleClicked是传递折射信号的方法。虽然我撤消了refractoring动作,但它仍然给出了这个错误。相同的代码确实运行了bofe。
我尝试过清理并运行qMake但没有成功。甚至创建了一个新项目并复制粘贴文件内容但仍然遇到了同样的错误。
这些是文件 -
mainwindow.h
#pragma once;
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
myqtimagewidget.h
#pragma once
#include <QWidget>
#include <QImage>
#include <QPainter>
#include <QtGui/QMouseEvent>
#include "opencv2/opencv.hpp"
class MyQtImageWidget : public QWidget
{
Q_OBJECT
protected:
QImage qimage;
cv::Mat temp;
void paintEvent(QPaintEvent*);
void mouseDoubleClicked(QMouseEvent* event);
// void mousePressEvent(QMouseEvent *event);
public:
explicit MyQtImageWidget(QWidget *parent = 0) : QWidget(parent) {}
QSize sizeHint() const {return qimage.size(); }
QSize minimumSizeHint() const {return qimage.size(); }
signals:
void signalMouseMoved(QString);
public slots:
void showImage(const cv::Mat &image);
};
myqtimagewidget.cpp
#include "myqtimagewidget.h"
#include "opencv2/opencv.hpp"
using namespace cv;
void MyQtImageWidget::showImage(const Mat &image)
{
//resize image to fit widget. Maintains aspect ratio
int width = this->maximumWidth();
int hight = this->maximumHeight();
Mat rescaledImg;
if(image.cols > width || image.rows > hight)
{
// debug info --v
QString data = "Original dimention: " + QString::number(image.cols) + "x" + QString::number(image.rows);
qDebug(data.toStdString().c_str());
// debug info --^
double aspectRatio = (double)image.cols / (double)image.rows; // width / height
cv::Size2i newSize;
// debug info --v
qDebug(std::to_string(width).c_str());
qDebug(std::to_string(hight).c_str());
// debug info --^
if(image.cols >= image.rows)
{
newSize = cv::Size(width, width / aspectRatio);
}
else
{
newSize = cv::Size(hight * aspectRatio, hight);
}
cv::resize(image, rescaledImg, newSize, 1, 1);
// debug info --v
data = "Resized dimention: " + QString::number(rescaledImg.cols) + "x" + QString::number(rescaledImg.rows);
qDebug(data.toStdString().c_str());
// debug info --^
}
else
rescaledImg = image;
// Convert the image to the RGB888 format
switch (rescaledImg.type())
{
case CV_8UC1:
cvtColor(rescaledImg, temp, CV_GRAY2RGB);
break;
case CV_8UC3:
cvtColor(rescaledImg, temp, CV_BGR2RGB);
break;
}
// QImage needs the data to be stored continuously in memory
assert(temp.isContinuous());
// Assign OpenCV's image buffer to the QImage. Note that the bytesPerLine parameter
// (http://qt-project.org/doc/qt-4.8/qimage.html#QImage-6) is 3*width because each pixel
// has three bytes.
qimage = QImage(temp.data, temp.cols, temp.rows, temp.cols*3, QImage::Format_RGB888);
repaint();
}
void MyQtImageWidget::paintEvent(QPaintEvent *event)
{
// Display the image
QPainter painter(this);
painter.drawImage(QPoint(0,0), qimage);
painter.end();
}
void MyQtImageWidget::mouseDoubleClicked(QMouseEvent *event)
{
int x = event->pos().x(), y = event->pos().y();
QString data = "x: " + QString::number(x) + ", y: " + QString::number(y);
emit MyQtImageWidget::signalMouseMoved(data);
}
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "opencv2/opencv.hpp"
#include "myqtimagewidget.h"
using namespace cv;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QString imageSrc = "E:\\Images\\Panorama\\Harshil3578_stitch.jpg";
Mat image = imread(imageSrc.toStdString(), IMREAD_COLOR);
}
MainWindow::~MainWindow()
{
delete ui;
}
在GUI中,我将小部件提升为MyQtImageWidget
并连接到QLabel。
答案 0 :(得分:1)
考虑链接器告诉你的内容:
问题是QWidget 不有一个名为mouseDoubleClicked的虚拟方法。我最好的猜测是,在你的重构过程中,你以某种方式修改了QWidget的头文件,将现有的虚函数重命名为mouseDoubleClicked。
如果是这样的话,获取qwidget.h的新副本(或重新安装Qt)可以解决问题。