2021-05-08 QObject::connect: No such slot QSpinBox::(setValue(int))

#include "widget.h"

#include 
#include
#include
#include
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

        QWidget *window = new QWidget;
        window->setWindowTitle("Enter Your Age");




        QSpinBox *spinBox = new QSpinBox(window);
        QSlider *slider = new  QSlider(window);
        spinBox->setRange(0,130);
        slider->setRange(0,130);
        slider->setOrientation(Qt::Horizontal);

        //代码1
        QObject::connect(spinBox,SIGNAL(valueChanged(int)),slider,SLOT((setValue(int))));
        QObject::connect(slider,SIGNAL(valueChanged(int)),spinBox,SLOT((setValue(int))));
        
        //代码2
//        QObject::connect(spinBox,SIGNAL(valueChanged(int)),slider,SLOT(setValue(int)));
//        QObject::connect(slider,SIGNAL(valueChanged(int)),spinBox,SLOT(setValue(int)));

        //代码1和代码2 的区别就是在SLOT对应的括号中多加了一个括号,就导致了信号无法通信
        slider->setValue(35);
        QHBoxLayout *layout = new QHBoxLayout;
        layout->addWidget(spinBox);
        layout->addWidget(slider);
        window->setLayout(layout);


        window->show();
    return a.exec();
}

代码1在运行的时候是QSliter和QSpinBox之间是无法通信的,提示QObject::connect: No such slot QSpinBox::(setValue(int)),而代码2就可以它们仅仅是因为在SLOT中多加了一个括号。

运行代码1

2021-05-08 QObject::connect: No such slot QSpinBox::(setValue(int))_第1张图片

运行代码2

2021-05-08 QObject::connect: No such slot QSpinBox::(setValue(int))_第2张图片

 

你可能感兴趣的:(QT,QT中connect出错)