2012-11-30 9 views
0

QPushButton의 신호를 슬롯 QGraphicsView에 연결하는 데 문제가 있습니다.QPushButton 신호를 QGraphicsView 슬롯에 연결하는 중 문제가 발생했습니다.

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 

언제 :

내 푸시 버튼 헤더는 다음과 같이 찾을 수 없습니다

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에 대한 참조를 점점 계속 매크로를 꺼내면 컴파일 할 수 있지만 실행하면이 오류가 계속 발생합니다.

Object::connect: No such signal QPushButton::updated() in implementation/game_controller.cpp:11 
여기 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())); 

어떤 도움을 크게

+0

자식의 모든 클래스에서 사용할 수있는) (신호가 클릭 처리하지 마십시오. 신호/슬롯이 작동하려면 확실히 Q_OBJECT가 필요합니다. 다시 넣은 후에 qmake를 다시 실행 했습니까? 실제로는 편집증에서 벗어나 "깨끗하게 정리하고 확인하십시오." 나는 93 % 만 확신했기 때문에 이것을 답으로 쓰지는 않았지만 그것을 고칠 것이라고 생각합니다. –

+0

@ MarkStevens가 방금 시도 했는데도 전에와 같은 vtable 오류가 누락되었습니다. – JonMorehouse

+0

확인, Qt에서이 두 번째로 가장 일반적인 이유는 메시지가 실제로 말하는 것과 비슷합니다. 가상 메서드가 정의되었지만 구현되지 않았기 때문입니다. mousePressEvent()에 구현이 있습니까? 생성자/소멸자는 어떻습니까? –

답변

1

가 Q_OBJECT를 유지, 당신은 MOC 위해 필요 주시면 감사하겠습니다

돈 당신의 신호의 몸체를 쓰지 마라. moc은 모든 신호를위한 코드를 생성한다.

는 mousePressedEvent을 처리 QAbstractButton 나는이 걸려 넘어했습니다