Frage

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?

War es hilfreich?

Lösung 2

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.

Andere Tipps

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.)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top