2012-09-18 3 views
2

클릭 할 때 QSignalMapper를 사용하여 신호 발신자 (QPushButton)를 슬롯에 보내려고합니다. 그러나 그것은 효과가 없으며, 나는 왜 그런지 정말로 모릅니다.Qt QSignalMapper가 작동하지 않습니다.

이 작업을 수행하는 다른 방법을 알고 있다면 알려 주시면 좋겠지 만 앞으로는 유용 할 수 있으므로 QSignalMapper를 사용하는 방법을 알고 싶습니다.

moviebase.h

#ifndef MOVIEBASE_H 
    #define MOVIEBASE_H 

    #include <QtGui/QMainWindow> 
    #include <Qt\qsignalmapper.h> 

    #include "ui_moviebase.h" 
    #include "include\DBAdapter.h" 
    #include "include\objView.h" 

    class MovieBase : public QMainWindow 
    { 

     Q_OBJECT 

    public: 
     MovieBase(QWidget *parent = 0, Qt::WFlags flags = 0); 
     ~MovieBase(); 

    private: 

     Ui::MovieBaseClass ui; 

     DBAdapter *db; 
     DBAdapter::Type type; 
     QPushButton *buttonChecked; 
     QSignalMapper *pushButtonMapper; 

     void setMainButtonsFunct(); 


    private slots: 
     void button_pushed(const QPushButton &); 

    }; 

    #endif // MOVIEBASE_H 

moviebase.cpp

#include "moviebase.h" 

MovieBase::MovieBase(QWidget *parent, Qt::WFlags flags) 
    : QMainWindow(parent, flags) 
{ 
    ui.setupUi(this); 
    db = new DBAdapter(); 

    this->type = DBAdapter::Movie; 

    this->setMainButtonsFunct(); 

    ObjView *obj = new ObjView(this->ui.objView); 

    obj->view(db->get_All_Elements(this->type)); 
} 

void MovieBase::setMainButtonsFunct() 
{ 
    this->buttonChecked = ui.watchedButton; 

    this->pushButtonMapper = new QSignalMapper(this); 

    connect(this->ui.watchedButton, SIGNAL(clicked()), this->pushButtonMapper, SLOT(map())); 
    connect(this->ui.towatchButton, SIGNAL(clicked()), this->pushButtonMapper, SLOT(map())); 
    connect(this->ui.availableButton, SIGNAL(clicked()), this->pushButtonMapper, SLOT(map())); 
    connect(this->ui.allButton, SIGNAL(clicked()), this->pushButtonMapper, SLOT(map())); 

    this->pushButtonMapper->setMapping(this->ui.watchedButton, this->ui.watchedButton); 
    this->pushButtonMapper->setMapping(this->ui.towatchButton, this->ui.towatchButton); 
    this->pushButtonMapper->setMapping(this->ui.availableButton, this->ui.availableButton); 
    this->pushButtonMapper->setMapping(this->ui.allButton, this->ui.allButton); 

    connect(this->pushButtonMapper, SIGNAL(mapped(const QPushButton &)), this, SLOT(button_pushed(const QPushButton &))); 
} 

void MovieBase::button_pushed(const QPushButton &sender) 
{ 
    qDebug() << "button pushed"; 
    this->ui.watchedButton->setChecked(false); 
} 

MovieBase::~MovieBase() 
{ 

} 
+0

http://stackoverflow.com/questions/12173153/qt-dynamic-widgets-signal-and-slot-connection/12173296#12173296 – shan

답변

4

에만 QSignalMapper에 존재하는 신호를 사용할 수 있습니다. 그러한 신호가 없습니다 mapped(const QPushButton&). mapped(QWidget*)을 사용하고 슬롯이 동일한 서명 (예 : button_pushed(QWidget*))으로 변경하십시오.

+0

thx 많이있어, 지금 일해 : D 조 –

0

모두 좋은 것처럼 보입니다. 컴파일러 출력을 참조하십시오. 신호/슬롯 서명을 잘못 정의했을 수도 있습니다.

관련 문제