Qt信号/插槽配置

时间:2016-05-06 18:47:15

标签: c++ qt configuration qmake moc

我在Qt 5.6.0中有信号/插槽的问题

当我尝试编译时,我收到以下错误: 我用谷歌搜索了,当我使用qmake时发现了(我相信情况就是如此)然后我必须做一些moc欺骗,但作为一个强大的Qt初学者我没有找到合适的解决方案。

错误输出:

loadtexview.obj:-1: error: LNK2019: unresolved external symbol "public: void __cdecl LoadTexView::TexSend(class QPixmap)" (?TexSend@LoadTexView@@QEAAXVQPixmap@@@Z) referenced in function "public: virtual void __cdecl LoadTexView::paintGL(void)" (?paintGL@LoadTexView@@UEAAXXZ)

loadtexview.h:

#ifndef LOADTEXVIEW_H
#define LOADTEXVIEW_H

#include <QtOpenGL/QtOpenGL>


class LoadTexView : public QGLWidget
{
public:
    LoadTexView(QWidget *parent = 0);
    void paintGL();
signals:
    void TexSend(QPixmap sending);
};

#endif // LOADTEXVIEW_H

loadtex.cpp

...
void LoadTexView::paintGL()
{
    int w1 = width();
    int h1 = height();
    int w2,h2;
    float r1 = (float) w1 / (float) h1;
    float r2 = 1;

    w2 = w1;
    h2 = (float) w2 / r2;

    if(h2 > h1)
    {
        h2 = h1;
        w2 = (float) h2 * r2;
    }

    QPixmap tex = QPixmap("C:\\Users\\Gabor\\OneDrive\\Documents\\TexGen\\TexGen\\road.bmp");
    emit TexSend(tex);
...

连接mainwindow.cpp中的信号和插槽:

myLoadView = new LoadTexView();
myGenView = new GenTexView();
QHBoxLayout *TWrapper = new QHBoxLayout;
TWrapper -> addWidget(myLoadView);
ui->LoadedTexture->setLayout(TWrapper);

QObject::connect(myLoadView, SIGNAL(TexSend(QPixmap)),
                 myGenView,      SLOT(gotTexture(QPixmap)));

任何人都知道如何解决这个问题?我相信它只是一个moc配置,但是,我不知道如何解决它。其他一切对我来说都很好。

0 个答案:

没有答案