2

QSignalMapper を使用して、クリックされたときにシグナル送信者 (QPushButton) をスロットに送信しようとしています。しかし、それは機能せず、その理由は本当にわかりません。

これを行う別の方法を知っている場合は、お知らせいただければ幸いですが、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()
{

}
4

2 に答える 2

5

QSignalMapper に存在するシグナルのみを使用できます。そのような信号はありませんmapped(const QPushButton&)mapped(QWidget*)スロットを使用して変更し、同じ署名を持つようにします: button_pushed(QWidget*).

于 2012-09-18T09:15:17.390 に答える
0

すべて良さそうです。コンパイラ出力を参照してください。多分あなたは間違ったシグナル/スロット署名を定義しています

于 2012-09-18T09:29:20.007 に答える