1
votes

I made a class in a header file.

the class declaration:

class myTimer : public QObject
{
    Q_OBJECT
    ~snipped~

I have a custom slot:

private slots:
    void mySlot();

and a custom signal:

signals:
    QString mySignal();

The slot simply emits mySignal which then returns a QString.

I connect a QPushButton with mySlot:

connect(ui->startButton, SIGNAL(clicked()),
        timer, SLOT(mySlot()));

and mySignal to a LCD number:

connect(timer, SIGNAL(mySignal()),
        ui->lcdNumber, SLOT(display(QString)));

Here timer is the object of the class I've declared. In both the connect statements I'm getting the error unable to convert parameter to const QObject* pointing to the object 'timer'.

I don't know why this error is occurring even though I have properly derieved from QObject adn added Q_OBJECT macro.

2
How did you declare timer exactly? - Mat
The answer to your immediate problem is provided by David Schwartz, but what you are doing still won't work as the connect call expects the signal to provide a QString - which it doesn't. The signals carry their data as arguments, not return values (see a simple example: qt-project.org/doc/qt-5/signalsandslots.html#a-small-example). - cmannett85

2 Answers

4
votes

The connect function's first parameter is supposed to be a const QObject*. There's no way to convert a myTimer to a const QObject * because one of them is an object and the other is a pointer. You probably want &timer.

1
votes

signals can't return any value (the return value should be void)

if you want to pas a value through a signal then you should add a parameter:

signals:
    void mySignal(QString);

and then connect as:

connect(timer, SIGNAL(mySignal(QString)),
        ui->lcdNumber, SLOT(display(QString)));