docker1
docker1

Reputation: 13

Qt and "No such slot" error

I wrote the class and add a slot:

class graphShow : public QObject {
  Q_OBJECT
public:
  graphShow(){}
public slots:
  void upd(QGraphicsScene &S);
};

Implementation of graphShow::upd is here:

void graphShow::upd(QGraphicsScene &S) {
    QGraphicsTextItem* pTextItem = S.addText("Test");
    pTextItem->setFlags(QGraphicsItem::ItemIsMovable);
}

Connection:

graphShow gr;
QPushButton* p1 = new QPushButton("Show");
/*...*/
QObject::connect(p1,SIGNAL(clicked()),&gr,SLOT(upd(&scene);));

During compiling I have no errors but when program starts I see this message:

Object::connect: No such slot graphShow::upd(&scene); in main.cpp:93

What am I doing wrong?

Upvotes: 1

Views: 194

Answers (2)

Dmitry Sazonov
Dmitry Sazonov

Reputation: 8994

By the way, you doing it wrong. You could not connect signal without arguments to slot with argument. For your case you should use QSignalMapper.

Upvotes: 1

vahancho
vahancho

Reputation: 21220

You need to set up connection in the following way:

QObject::connect(p1, SIGNAL(clicked()), &gr, SLOT(upd(QGraphicsScene &)));

However this also may not wark, because Qt docs state:

The signature of a signal must match the signature of the receiving slot. (In fact a slot may have a shorter signature than the signal it receives because it can ignore extra arguments.)

Upvotes: 2

Related Questions