Signal / Slot problem



  • Hello everyone,

    I don't usualy come ask for help in forum but... Well I don't understand what I've done wrong and I'm out of idea. So here we go :
    I have two class and they have thoses problematics elements :

    class BridgeWin : public QDialog
    [...]
    public slots:
        void receiveInPos(int x, int y);
        void receiveOutPos(int x, int y);
    [...]
    
    class GraphicsView : public QGraphicsView
    [...]
    signals:
        void sendInPos(int x, int y);
        void sendOutPos(int x, int y);
    [...]
    

    They are each only used once, here all the instance :

    [...]
    void BridgeWin::receiveInPos(int x, int y)
    {
        qDebug() << "received";
        int cellRow = selectionCellInView->currentIndex().row();
        int bridgeRow = bridgeView->currentIndex().row();
        if(cellRow>=0 && bridgeRow>=0)
        {
            Cell *c = data->rowToCell(cellRow);
            c->bridgeList.at(bridgeRow)->setPointA(QPoint(x,y));
        }
    }
    void BridgeWin::receiveOutPos(int x, int y)
    {
        qDebug() << "received";
        int cellRow = selectionCellInView->currentIndex().row();
        int bridgeRow = bridgeView->currentIndex().row();
        if(cellRow>=0 && bridgeRow>=0)
        {
            Cell *c = data->rowToCell(cellRow);
            c->bridgeList.at(bridgeRow)->setPointB(QPoint(x,y));
            c->bridgeList.at(bridgeRow)->setID_b(data->cellRowToId(cellRow));
        }
    }
    [...]
    
    [...]
    void GraphicsView::ApplyBridgeTile()
    {
        Cell *c;
        if(cellIdBridgeIn >= 0)
        {
            c = data->idToCell(cellIdBridgeIn);
            if(pos.x() >= 0 && pos.y() >= 0 && pos.x() < c->tx && pos.y() < c->ty)
            {
                qDebug() << "sending : " << pos.x() << pos.y();
                emit sendInPos(pos.x(),pos.y());
                qDebug() << "send";
            }
        }
        else
        {
            c = data->idToCell(cellIdBridgeOut);
            if(pos.x() >= 0 && pos.y() >= 0 && pos.x() < c->tx && pos.y() < c->ty)
            {
                qDebug() << "sending : " << pos.x() << pos.y();
                emit sendOutPos(pos.x(),pos.y());
                qDebug() << "send";
            }
        }
    }
    [...]
    

    So the problem is, despite the fact that I connected them :

    [...]
    connect(view, SIGNAL(sendInPos(int, int)), menuBar->bridgeWin, SLOT(receiveInPos(int, int)));
    connect(view, SIGNAL(sendOutPos(int, int)), menuBar->bridgeWin, SLOT(receiveOutPos(int, int)));
    [...]
    

    I allways get in the console (with the value I intended for x and y) :
    sending : x y
    send

    It never reach the "received" pole. What did I miss? Why all my others signals and slots are working just fine and not thoses four?

    Thanks you for you're intention and sorry for my poor english, it's not my native language.



  • Hi @DPixel ,

    Have u used Q_OBJECT macro in the class , just to ensure on the safer side. ?

    Thanks,



  • Yes, and in fact the class

    class BridgeWin : public QDialog
    
    class GraphicsView : public QGraphicsView
    

    (and this one that have hold the connection above)

    class MainWindow : public QMainWindow
    

    are all related to the problem in some point and have a lot of signal and slots working just fine. I bet it doesn't work because of something stupid I shouldn't have done but I can't find what...



  • Nevermind, it was indeed stupid. In fact I have 3 instance of "GraphicsView" :
    one for editing map.
    two for creating path beatween map.

    So I rewired it and now it works.

    Sorry for wasting your time and thanks trying to help me.



  • @DPixel please don't forget to mark your post as solved! Thanks


Log in to reply