2

我正在尝试制作一些自定义插槽,但它抱怨自定义插槽不存在。

我用谷歌搜索,但找不到任何类似情况的东西。没有解决方案对我有用。

QObject::connect: No such slot QSlider::setMinimum(int)

墨水木偶.cpp

#include "inkpuppet.h"
#include "ui_inkpuppet.h"
#include "aboutdialog.h"

#include <QDialog>
#include <QWidget>
#include <QtCore>
#include <QtGui>
#include <QButtonGroup>
#include <QSlider>

InkPuppet::InkPuppet(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::InkPuppet)
{
    ui->setupUi(this);
    connect(ui->lowerFrameBox, SIGNAL(valueChanged(int)), ui->timeSlider, SLOT(setMinimum(int)));
    connect(ui->upperFrameBox, SIGNAL(valueChanged(int)), ui->timeSlider, SLOT(setMaximum(int)));
    //connect(ui->lowerFrameBox, SIGNAL(valueChanged(int)), ui->timeSlider, SLOT(setRange(int,int)));
}

InkPuppet::~InkPuppet()
{
    delete ui;
}

void InkPuppet::on_aboutButton_clicked()
{

}

void InkPuppet::setMinimum(int value)
{
    ui->timeSlider->setMinimum(value);
}

void InkPuppet::setMaximum(int value)
{
    ui->timeSlider->setMaximum(value);
}

墨水木偶.h

#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QtCore>
#include <QtGui>

#include "aboutdialog.h"

namespace Ui {
class InkPuppet;
}

class InkPuppet : public QWidget
{
    Q_OBJECT



public:
    explicit InkPuppet(QWidget *parent = 0);
    ~InkPuppet();

public slots:
    void on_aboutButton_clicked();
    void setMinimum(int value);
    void setMaximum(int value);

private:
    Ui::InkPuppet *ui;
    AboutDialog *aDialog;


};

#endif // WIDGET_H
4

2 回答 2

3

您尝试将ui->lowerFrameBox valueChanged(int)信号与 .setMinimum 中的插槽连接ui->timeSlider。但是,setMinimum 没有槽。您需要连接到 InkPuppet 中的插槽。

connect(ui->lowerFrameBox, SIGNAL(valueChanged(int)), 
 this, SLOT(setMinimum(int)));
于 2013-08-25T11:01:39.567 回答
0

在 Qt 5.1 中,您也可以通过以下方式使用连接:

 connect(ui->upperFrameBox,&QSlider::valueChanged,this,&InkPuppet::setMaximum);

 connect(ui->upperFrameBox,&QSlider::valueChanged,&InkPuppet::setMaximum);

甚至您可以使用 c++11 lambda 功能。

connect(ui->upperFrameBox,&QSlider::textChanged,
                      [&](int value) {ui->timeSlider->setMaximum(value);});
于 2013-08-25T12:01:42.277 回答