1

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;
}

And this are the related source parts:

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;
}

and I get the error:

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

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?

dhein
  • 6,431
  • 4
  • 42
  • 74
  • 1
    You forgot to add `Q_OBJECT` to your `RenderGraphFrame` class. Run qmake after you do that. – vahancho Jul 22 '15 at 11:40
  • Well.... that fixed it. Never heared of that (But I'm new to qt). Does any class have to contain it while working with QT? – dhein Jul 22 '15 at 11:42
  • 1
    Not any class, but if you use specific Qt features, like slots or QVariant, you have to add it – Viktor Jul 22 '15 at 11:44
  • @Viktor That's misleading. `QVariant` doesn't enter the picture anywhere. It's really simple: **Any class deriving from `QObject` must include `Q_OBJECT` macro in the first line of class's definition.** Nothing to it. It's literally that simple. The confusion around this simple subject is mind-boggling. – Kuba hasn't forgotten Monica Jul 22 '15 at 20:20

1 Answers1

3

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:

Community
  • 1
  • 1
Antwane
  • 20,760
  • 7
  • 51
  • 84