I'm stuck with an error and i have no idea where I am going wrong i tried running the signal with qapp aswell just to make sure it isn't the signal, and that was all fine. I have the SLOT declared as a public slot in my header file.
signal declaration:
void editPolygon(QVector <QPointF> points, QPolygonF &);
this is my connect:
connect(this, SIGNAL(editPolygon(QVector <QPointF> &, QPolygonF &)), parent, SLOT(editPolygon(QVector <QPointF> points, CustomPolygon *poly)));
this is my slot thats emmiting the signal:
void CustomPolygon::editPolygons()
{
QVector<QPointF> points;
QPolygonF poly = mapToScene(polygon());
emit editPolygon(points,poly);
}
and this is the void in mainwindow.cpp:
void MainWindow::editPolygon(QVector<QPointF> &points, CustomPolygon *poly)
{
}
thanks for you help in advance!
The first thing I would do is look very hard at the discrepancy in the second parameter of your signal/slot match.
One is QPolygon&
and the other is CustomPolygon*
. My understanding is that these had to match. Even if one were a proper subclass of the other, I don't think you can mix references and pointers like that.
And,regarding your (slightly paraphrased) comment:
My slot has to stay as a pointer because it points to an item that is being deleted from a
QGraphicsScene
.My signal cant be a pointer because there is no conversion from a
QPolygonF
to aQPolygonF *
, and I requireQPolygonF
tomapToScene
.
I think I understand what you're saying, and there are a couple of issues.
If your slot takes a pointer that will be freed, you have to give it a pointer, and relinquish control of the object behind it (so either start with a dynamically allocated copy you're willing to let go of, or make a dynamically allocated copy from something you don't want to let go of).
And I'm not sure why you think there's no conversion from the object to a pointer to that object. I suppose that's technically true since the class itself doesn't provide a conversion, but this is really part of the base language:
Type thing;
Type *pointerToThing = &thing;
Both those issues should be solvable with something like:
QVector<QPointF> points;
QPolygonF thisIsMyPoly = mapToScene(polygon());
QploygonF *thisIsPolyForFreeing = new QPolygonF(thisIsMyPoly);
emit editPolygon(points, thisIsPolyForFreeing);
Your signal will still have to be changed to use a pointer rather than a reference and, hopefully, that will alleviate the mismatch.
If your pointer is an actual pointer to a QPolygonF
that cannot be copied (because it's the pointer to the actual item being held in the QGraphicsScene
and you therefore need the original pointer to remove it), I think you should just be able to pass that pointer as-is, assuming mapToScene()
is returning a reference to it rather than a copy:
QPolygonF poly = mapToScene(polygon()); // get ref.
emit editPolygon(points, &poly); // pass ref's address.