|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- #include "widget.h"
- #include "ui_widget.h"
- Widget::Widget(QWidget *parent)
- : QWidget(parent)
- , ui(new Ui::Widget)
- {
- ui->setupUi(this);
- ui->comboBox->addItem("10");
- ui->comboBox->addItem("11");
- ui->comboBox->addItem("12");
- ui->comboBox->addItem("13");
- ui->comboBox->addItem("14");
- connect(ui->comboBox,&QComboBox::currentIndexChanged,this,&Widget::onIndexStr); //这样也可以
- connect(ui->comboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &Widget::onIndex);
- connect(ui->comboBox, QOverload<const QString&>::of(&QComboBox::currentIndexChanged), this, &Widget::onIndexStr);
- connect(ui->comboBox, &QComboBox::currentTextChanged, this, &Widget::onIndexStr);
- // 使用泛型解决信号重载类型(一般使用这个)
- //connect(ui->comboBox,QOverload<int>::of(&QComboBox::currentIndexChanged),this,&Widget::onIndex);
- // connect(ui->comboBox,QOverload<const QString&>::of(&QComboBox::currentIndexChanged),this,&Widget::onIndexStr);
- // connect(ui->comboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &Widget::onIndex);
- // connect(ui->comboBox, QOverload<const QString&>::of(&QComboBox::currentTextChanged), this, &Widget::onIndexStr);
- }
- Widget::~Widget()
- {
- delete ui;
- }
- void Widget::onIndex(int index)
- {
- }
- void Widget::onIndexStr(const QString& index)
- {
- }
复制代码
报错在connect(ui->comboBox, QOverload<const QString&>::of(&QComboBox::currentIndexChanged), this, &Widget::onIndexStr);
报错提示:没有找到匹配的重载函数,但是不是已经跟它的类型匹配了吗 |
|