QT“没有这样的时隙”错误 [英] QT "No such slot" Error

查看:172
本文介绍了QT“没有这样的时隙”错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的类定义/ .hpp文件的一部分:

This is the part of my Class definition/.hpp file:

class RenderGraphFrame : public QGLWidget
{
public:
    RenderGraphFrame(QWidget *parent);

private slots:
    void PrevButton();
    void NextButton();

private:
    void draw();
    QWidget *p_parent;
    bool ButtonsInited;
    QPushButton *nextButton;
    QPushButton *prevButton;
}

这是相关的来源部分:

RenderGraphFrame::RenderGraphFrame(QWidget *parent)
    : QGLWidget(QGLFormat(/*QGL::SampleBuffers*/), parent)
{
    p_parent = parent;
    /* ... */
}


void RenderGraphFrame::draw()
{
    if (ButtonsInited == false)
    {
        bool tmpttest_success;
        nextButton = parent->findChild<QPushButton *>("nextButton", Qt::FindChildrenRecursively);
        prevButton = p_parent->findChild<QPushButton *>("prevButton", Qt::FindChildrenRecursively);
        tmpttest_success = connect(_nextButton, SIGNAL (released()), this, SLOT(NextButton()));

        if (tmptest_success == false)
        {
            //this is what happens but I don't want it to happen...
        }
    }
    /*....*/
}


void RenderGraphFrame::NextButton()
{
    /*somestuff*/
    return;
}

void RenderGraphFrame::PrevButton()
{
    /*somestuff*/
    return;
}

我得到错误:

QObject::connect: No such slot QGLWidget::NextButton() in ..\Graph\some\path\to.cpp:160
QObject::connect:  (sender name:   'nextButton')

Ofcouse没有,因为我不想连接 QGLWidget :: NextButton(),因为我想连接 RenderGraphFrame :: NextButton()
我如何解决这个问题?我已经锁定了所有这些帖子关于没有这样的槽qt错误。

Ofcouse there isn't, because I don't want to connect QGLWidget::NextButton(), as I want to connect RenderGraphFrame::NextButton(). How I can solve this? I allready locked up all these posts about "no such slot" qt errors. but they seemed to be at all caused by other problems than mine.

那么任何建议如何解决这个问题?

So any suggestions how to fix this?

推荐答案

如注释中所述,您必须在类声明中添加 Q_OBJECT 宏。互联网上的许多文档将帮助您了解为什么需要这样做:

As explained in the comments, you have to add the Q_OBJECT macro in the class declaration. Many doc on the internet will help you to understand why this is necessary:

  • When should Q_OBJECT be used?
  • http://doc.qt.io/qt-5/qobject.html#Q_OBJECT
  • http://doc.qt.io/qt-5/metaobjects.html

这篇关于QT“没有这样的时隙”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆