首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未定义对`Histogram::`Histogram(QWidget*)的引用

未定义对`Histogram::`Histogram(QWidget*)的引用
EN

Stack Overflow用户
提问于 2017-05-24 05:03:48
回答 1查看 312关注 0票数 0

我正在尝试使用qmake和make为uEye相机编译一个相机软件。

我的qmake命令运行良好,但是当我在命令行中键入make时得到以下错误

代码语言:javascript
复制
make[1]: Entering directory '/usr/src/ids/ueyedemo'
g++ -m64 -Wl,-O1 -o ueyedemo release/tabxs.o release/tabsizexs.o release/tabcamera.o release/tabimage.o release/tabsize.o release/tabprocessing.o release/tabformat.o release/tabio.o release/qsliderex.o release/imageinfodlg.o release/properties.o release/cameralist.o release/main.o release/mainview.o release/eventthread.o release/paintlabel.o release/tabhotpixel.o release/moc_qsliderex.o release/moc_imageinfodlg.o release/moc_properties.o release/moc_cameralist.o release/moc_mainview.o release/moc_eventthread.o release/moc_paintlabel.o release/qrc_mainview.o    -L/usr/lib/x86_64-linux-gnu -L/usr/X11R6/lib64 -lueye_api -lQtOpenGL -lQtGui -lQtCore -lGL -lpthread 
release/mainview.o: In function `Mainview::onHistogram(bool)':
mainview.cpp:(.text+0x1ada): undefined reference to `Histogram::Histogram(QWidget*)'
release/mainview.o: In function `Mainview::DrawImage(char*)':
mainview.cpp:(.text+0x87c1): undefined reference to `Histogram::updateHistogram(unsigned int, char*)'
collect2: error: ld returned 1 exit status
Makefile.Release:151: recipe for target 'ueyedemo' failed
make[1]: *** [ueyedemo] Error 1
make[1]: Leaving directory '/usr/src/ids/ueyedemo'
Makefile:34: recipe for target 'release' failed
make: *** [release] Error 2

有人能告诉我问题出在哪里吗?我在想我可能有错误的qt或qmake版本?

histogram.cpp

代码语言:javascript
复制
#include "histogram.h"
#include "ui_histogram.h"

#include <QPixmap>
#include <QPainter>
#include <QPen>
#include <QtCore/qmath.h>
#include <QMessageBox>
#include <QMap>

Histogram::Histogram(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Histogram)
{
    ui->setupUi(this);
    connect(ui->pushButtonClose, SIGNAL(clicked()), this, SLOT(close()));
    connect(ui->pushButtonClose, SIGNAL(clicked()), parent, SLOT(closeHistogram()));
    setWindowTitle("uEye Histogram");
}

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

bool Histogram::updateHistogram(HIDS hCam, char *pBuffer)
{
    uint32_t pixmapWidth = ui->labelHistogram->width();
    uint32_t pixmapHeight = ui->labelHistogram->height();
    QPixmap histogram(pixmapWidth, pixmapHeight);
    histogram.fill(Qt::lightGray);

    int nRet = IS_NO_SUCCESS, imageID = 0, colormode = 0;
    char* pImgMem = NULL;

    nRet = is_GetActSeqBuf(hCam, &imageID, 0, &pImgMem);
    if (nRet != IS_SUCCESS)
    {
        return false;
    }

    colormode = is_SetColorMode(hCam, IS_GET_COLOR_MODE);
    if (colormode == IS_CM_MONO8)
    {
        ui->checkBoxHistogramGreen->setEnabled(false);
        ui->checkBoxHistogramRed->setEnabled(false);
    }
    else
    {
        ui->checkBoxHistogramGreen->setEnabled(true);
        ui->checkBoxHistogramRed->setEnabled(true);
    }

    uint32_t steps = 0, channels = 3, valuesPerChannel = 256, maxValue = 0;
    uint32_t bgrBuffer[valuesPerChannel * channels];
    memset(bgrBuffer, 0, sizeof(bgrBuffer) / sizeof(bgrBuffer[0]));

    nRet = is_GetImageHistogram(hCam, imageID, colormode, bgrBuffer);
    if (nRet != IS_SUCCESS)
    {
        return false;
    }

    for (size_t channel = 0; channel < channels; channel++)
    {
        if ((channel == 0 && ui->checkBoxHistogramBlue->isChecked()) ||
            (channel == 1 && ui->checkBoxHistogramGreen->isChecked()) ||
            (channel == 2 && ui->checkBoxHistogramRed->isChecked()))
        {
            if (colormode == IS_CM_MONO8 && channel > 0)
            {
                continue;
            }

            uint32_t* buffer = bgrBuffer + (1 << 8) * channel;
            for (size_t i = 0; i < valuesPerChannel; i++)
            {
                if (buffer[i] > maxValue)
                {
                    maxValue = buffer[i];
                }
            }
        }
    }

    if (colormode == IS_CM_BGR565_PACKED)
    {
        ui->histogramLabel128->setText(QString::number((1 << 6) / 2));
        ui->histogramLabel255->setText(QString::number((1 << 6) - 1));
    }
    else
    {
        ui->histogramLabel128->setText("128");
        ui->histogramLabel255->setText("255");
    }

    QPainter painter(&histogram);
    QPen pen(Qt::DashLine);
    QPolygon polygon;
    std::vector<QColor> colors;

    colors.push_back(QColor("blue"));
    colors.push_back(QColor("green"));
    colors.push_back(QColor("red"));

    pen.setColor(Qt::gray);
    pen.setWidth(1);
    painter.setPen(pen);
    painter.setBrush(Qt::lightGray);
    painter.drawRect(0, 0, pixmapWidth, pixmapHeight);

    steps = 1 << int(log(pixmapWidth / 10.0f) / log(2.0f));
    for (int i = 1; i < steps; ++i)
    {
        painter.drawLine((pixmapWidth * float(i) / steps), 1, (pixmapWidth * float(i) / steps), pixmapHeight - 1);
    }

    steps = 1 << int(log(pixmapHeight / 10.0f) / log(2.0f));
    for (int i = 1; i < steps; ++i)
    {
        painter.drawLine(1, pixmapHeight * float(i) / steps, pixmapWidth - 1, pixmapHeight * float(i) / steps);
    }

    painter.setRenderHint(QPainter::Antialiasing);
    pen.setStyle(Qt::SolidLine);

    qreal scaleWidth = pixmapWidth / double(valuesPerChannel - 1);
    qreal scaleHeight = pixmapHeight / double(maxValue);

    for (size_t channel = 0; channel < channels; channel++)
    {
        if ((channel == 0 && ui->checkBoxHistogramBlue->isChecked()) ||
            (channel == 1 && ui->checkBoxHistogramGreen->isChecked()) ||
            (channel == 2 && ui->checkBoxHistogramRed->isChecked()))
        {
            if (colormode == IS_CM_MONO8 && channel > 0)
            {
                continue;
            }
            if (colormode == IS_CM_BGR565_PACKED)
            {
                if (channel == 1)
                {
                    scaleWidth = pixmapWidth / double(256 / 8 * 6 - 1) * 3.0;
                }
                else
                {
                    scaleWidth = pixmapWidth / double(256 / 8 * 5 - 1) * 3.0;
                }
            }

            uint32_t* buffer = bgrBuffer + (1 << 8) * channel;

            pen.setColor(colors[channel]);
            painter.setPen(pen);
            painter.setBrush(Qt::transparent);

            polygon.clear();
            polygon << QPoint(pixmapWidth, pixmapHeight) << QPoint(0, pixmapHeight);

            for (size_t i = 0; i < valuesPerChannel; i++)
            {
                polygon << QPoint(scaleWidth * i, pixmapHeight - scaleHeight * buffer[i]);
            }

            painter.drawPolygon(polygon);
        }
    }

    ui->labelHistogram->setPixmap(histogram);

    return false;
}

调用updateHistogram的mainview.cpp

代码语言:javascript
复制
if(m_pHistogramDlg != 0)
{
    m_pHistogramDlg->updateHistogram(m_hCamera, pBuffer);
}
EN

回答 1

Stack Overflow用户

发布于 2017-05-24 14:39:37

您可能忘记在.pro文件中的SOURCES中添加histogram.cpp

代码语言:javascript
复制
SOURCES += histogram.cpp

命令行输出的第二行提到了传递给链接器的所有文件,其中不包括histogram.o (即编译后的histogram.cpp)。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44144984

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档