0
votes

I have a Ui class with a function that i want to call every time i emit a signal from a class lets say test. in the ui function i need to connect my signal and slot but im trying the code from the QT docs and having no luck

signal declaration

signals:

void paint(int x, int y, int id);

signal emit

emit paint(x, y, id)

connection (m_test been a class object)

connect(&m_test,SIGNAL(paint(int,int,int)), this, SLOT(uiFunction(int,int,int)));

getting this error

error: C2664: 'QMetaObject::Connection QObject::connect(const QObject *,const char *,const QObject *,const char *,Qt::ConnectionType)' : cannot convert parameter 1 from 'uiFunction *' to 'const QObject *'

but i follwed this QT docs example (counter being the class)

Counter a, b;
     QObject::connect(&a, SIGNAL(valueChanged(int)),
                      &b, SLOT(setValue(int)));

any ideas?

1
It's saying your m_test type does not derive from QObject.cmannett85
ok but neither does the one in the example from QT docsAngryDuck
class Counter : public QObject... Try again.cmannett85
And don't forget Q_OBJECT macrosDmitry Sazonov

1 Answers

3
votes

You need your Ui class to inherit from QObject and then add the QOBJECT macro just after the declaration of the class. e.g.

class Ui : public QObject
{
    QOBJECT

signals:
    void paint(int x, int y, int id);

private slots:
    void UiFunction(int x, int y, int id);
};