[solved] Signal is not being recieved immediately.
-
I am having a problem where I emit a signal in a mouseMove event, but that signal does not get recieved by a slot on another object until i release the mouse.
Details:
I have a class calledSelectableItem, which subclassesQGraphicsObject:
@
class SelectableItem : public QGraphicsObject {
Q_OBJECT
public:
SelectableItem();void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) = 0; QRectF boundingRect() const = 0; signals: void moveItem(QGraphicsSceneMouseEvent *e); void deselectAllItems(); void deselectItem(Parts::SelectableItem*); void selectItem(Parts::SelectableItem*); void stopSelectionDrag(); void stopMovingParts(); void deleteSelectedItems(); protected: void mousePressEvent(QGraphicsSceneMouseEvent *e); void mouseReleaseEvent(QGraphicsSceneMouseEvent *e); void mouseMoveEvent(QGraphicsSceneMouseEvent *e); void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *e); void hoverEnterEvent(QGraphicsSceneHoverEvent *e); void hoverLeaveEvent(QGraphicsSceneHoverEvent *e); bool m_is_selected; bool m_is_hovering; bool m_is_selectable; };@I have two other classes that subclass the
SelectableItemclass. They arePartandTerminalPart:
@
class Part : public SelectableItem {
Q_OBJECT
public:friend class PartLabel; Part(); // Inherited Functions void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); QRectF boundingRect() const; void setPos(qreal x, qreal y); QGraphicsSvgItem* GetPartSvg(); signals: void partRotated(); private: // Inherited Functions void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *e); void hoverEnterEvent(QGraphicsSceneHoverEvent *e); void hoverLeaveEvent(QGraphicsSceneHoverEvent *e); void contextMenuEvent(QGraphicsSceneContextMenuEvent *e); };@Terminal:
@
class Terminal : public SelectableItem {
Q_OBJECT
public:
enum TerminalDirection {
North,
East,
South,
West
};Terminal(const std::string &name, const QPointF &rel_coords, const std::string &direction); // Inherited Functions void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); QRectF boundingRect() const; QPointF GetRelativeCoord(); QPointF GetConnectionCoord(); void SetPart(Part *p); bool HasPart(); void Move(); void RotateCW(); void RotateCCW(); void SetIsConnected(bool b); bool IsConnected(); void AddConnection(Connection *c); void RemoveConnection(Connection *c); std::list<Connection*> GetConnectionList(); signals: void connectionBegun(Parts::Terminal *t); void connectionCompleted(Parts::Terminal *t); private: // Inherited Functions void mouseReleaseEvent(QGraphicsSceneMouseEvent *e); void hoverEnterEvent(QGraphicsSceneHoverEvent *e); void hoverLeaveEvent(QGraphicsSceneHoverEvent *e); //void contextMenuEvent(QGraphicsSceneContextMenuEvent *e); void IncrementDirection(); void DecrementDirection(); QPointF m_rel_coords; QPointF m_rotated_rel_coords; bool m_is_connected; int m_direction; int m_rotation_angle; QRectF m_bounding_rect; Part *m_part; std::string m_name; std::list<Connection*> m_connections; };@The
SelectableItemclass's mouseMove function is as follows:
@
void SelectableItem::mouseMoveEvent(QGraphicsSceneMouseEvent *e) {
if(!m_is_selectable)
return;if(m_is_selected) emit moveItem(e); else { emit deselectAllItems(); emit selectItem(this); } }@The signal
emit selectItem(this)is instantly recieved by another classSysGraphicsScenewhich handles item selection.The problem I'm having is that the
Partclass emits this signal via its base class and the signal is recieved by theSysGraphicsSceneclass instantly. However, theTerminalclass emits this signal via it's base class (SelectableItem, which is the same base class thatParthas.) and the signal is not recieved instantly bySysGraphicsScenebut only after mouseReleased.I have no idea why two derived classes would work differently. Any ideas?
-
Hi and welcome to devnet,
Glad you found out and thanks for sharing the solution. Can you please also update the thread title prepending [solved] ? So other forum users may know a solution has been found :)