0

の信号QPushButtonを のスロットに接続できませんQGraphicsView

私のプッシュボタンヘッダー:

class Button : public QPushButton {

    Q_OBJECT

    public://public constructors / destructors

        Button(Game_state * game_state, QWidget *parent = 0);
        ~Button();

    protected://signals / slots etc QT 
        void mousePressEvent(QMouseEvent * event);//

    signals:
        void updated() { std::cout << "HELLO FROM THE UPDATED METHOD" << std::endl;}

    protected:
        Game_state * game_state;//this is the global gamestate method
        char * action_name;//this is the application name that is responsible for setting the game_state so the game controller knows what to delete / update

};

これをスロットでコンパイルするにはマクロが必要ですが、Q_Objectコンパイルすると、次のように vtable 参照が見つかりません。

Undefined symbols for architecture x86_64:
  "vtable for Button", referenced from:
      Button::~Button()in buttons.o
      Button::~Button()in buttons.o
      Button::~Button()in buttons.o
      Button::Button(Game_state*, QWidget*)in buttons.o
      Button::Button(Game_state*, QWidget*)in buttons.o

マクロを取り出すと、問題なくコンパイルできますが、実行すると次のエラーが発生し続けます。

Object::connect: No such signal QPushButton::updated() in implementation/game_controller.cpp:11

私のgame_controller拡張QGRaphicsViewとここにボタンを接続しようとしている私のコードがあります:

this->button = new Button(game_state);
this->proxy = new QGraphicsProxyWidget();
this->proxy = this->scene->addWidget(this->button);

connect(this->button, SIGNAL(updated()), this, SLOT(update()));

どんな助けでも大歓迎です

4

1 に答える 1

1

Q_OBJECTを保持します、あなたはmocのためにそれを必要とします

シグナルの本文を記述しないでください。mocはすべてのシグナルのコードを生成します。

mousePressedEventを処理せず、QAbstractButtonとそのすべての子クラスで使用可能なクリックされたシグナル()を処理します

于 2012-12-01T01:59:52.890 に答える