gpt4 book ai didi

c++ - Qt QSignalMapper 不工作

转载 作者:搜寻专家 更新时间:2023-10-31 00:42:01 24 4
gpt4 key购买 nike

我正在尝试使用 QSignalMapper 在单击时将信号发送器 (QPushButton) 发送到插槽。但它不起作用,我真的不知道为什么。

如果您知道执行此操作的不同方法,很高兴通知我,但我真的很想知道如何使用 QSignalMapper,因为它在将来很有用。

电影库.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

电影库.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()
{

}

最佳答案

您只能使用 QSignalMapper 中存在的信号。没有这样的信号 mapped(const QPushButton&)。使用 mapped(QWidget*) 并将您的插槽更改为具有相同的签名:button_pushed(QWidget*)

关于c++ - Qt QSignalMapper 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12473718/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com