簡體   English   中英

將QPushButton信號連接到QGraphicsView插槽時出現問題

[英]Trouble Connecting QPushButton Signal to QGraphicsView Slot

我在將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 ,這是我嘗試連接Button的代碼:

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()));

任何幫助將不勝感激

保留Q_OBJECT,moc需要它

不要寫信號的主體,moc會為所有信號生成代碼。

不處理mousePressedEvent,處理在QAbstractButton及其所有子類上可用的clicked()信號

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM