View Full Version : Problems with signals and slots

25th September 2011, 16:52
I have the following problem. I have several graphics items with clicked signal with pointer to item and one slot at the main form to which I connect those signals. But when I push buttons qt always calls connection with the pointer of the first added button. Did anyone face this problem? I want to add that it is not the first time I'm facing the same strange behavior.

25th September 2011, 17:47
Please post some relevant code.

26th September 2011, 09:44
Signals and slots are connected within the constructor of the class that is not QObject-based.

SchemeColumn::SchemeColumn(QGraphicsScene* scn)
Scene = scn;

additembutton = new GraphicsPixmapButton(QPixmap(":/Items/Pixmaps/Add Round.png"));
additembutton->setData(SchemeColumns.count() - 1);
connect(additembutton, SIGNAL(clicked(GraphicsButton*)), this, SLOT(column_AddItemButton_clicked(GraphicsButton*) ));

pix.load(":/Scheme/Pixmaps/Loader Box.png");

But when I do something like this:

SchemeColumn::SchemeColumn(QGraphicsScene* scn, QObject* parent)

Everything works ok.
It turns out, that signals and slots should be connected within widgets.

26th September 2011, 09:52
...It turns out, that signals and slots should be connected within widgets.
If you need to connect from non-QObject classes or other places (like main function) you can use the syntax: QObject::connect(...)