0
votes

I have a project on Qt that has a GUI with a QGraphicsView. Then, I have a class called 'GraphicsScene' that is a subclass of 'QGraphicsScene'. After, I have a class called 'Entidade' that is a subclass of 'QGraphicsItemGroup'.

When I click on the GraphicsView, I add a new item of 'Entidade'. I wanna control the movement of the item on GraphicsView and for this I created a bool variable on 'Entidade.h' called movable and a slot called void setMovable(bool toggled). So, when the action is 'true' I can move the item, otherwise (example, other action is selected), can't move the item.

On class 'GraphicsScene', I create a signal called void setMovable(bool toggled).

So, I tried this:

MainWindow.cpp

connect(ui->actionMover, SIGNAL(toggled(bool)),
        graphicsScene, SIGNAL(setMovable(bool)));

GraphicsScene.cpp

connect(this,    SIGNAL(setMovable(bool)),
        entidade, SLOT(setMovable(bool))); //entidade is a item to add to graphicsview

Entidade.h

class Entidade : public QGraphicsItemGroup
{

public:
    Entidade();
    Entidade(qreal x, qreal y, qreal w, qreal h);

private:
    bool movable; //variavel para controlar o mover.

    QGraphicsRectItem *entidade;
    QGraphicsSimpleTextItem *texto;
    void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);

public slots:
    void setMovable(bool toggled);
};

At this point, when I try to run the project, this wild error appear:

E:\QTProjects\fcTables\graphicsscene.cpp:63: error: no matching function for call to 'GraphicsScene::connect(GraphicsScene* const, const char*, Entidade*&, const char*)'
                     entidade, SLOT(setMovable(bool)));
                                                     ^

followed by this one:

C:\Qt\Qt5.1.1\5.1.1\mingw48_32\include\QtCore\qobject.h:214: error: no type named 'Object' in 'struct QtPrivate::FunctionPointer<const char*>'

I think it happens 'cause the class 'Entidade' is not a subclass of QObject (creating it using 'Qt new class', type information field was 'None')

Someone knows how to solve?

P.S.: if more information is needed, ask for it. =D

1

1 Answers

-1
votes

Have you tried the built in drag and drop toggles of QGraphicsItem instead reinventing the mechanism? QGraphicsItemGroup should have it too.

Qt: qgraphicsitem drag and drop

Set the flags properly and it should work.

Hope that helps.