• QT 关联QComboBox的currentIndexChanged时遇到 成员指针指向重载指针函数问题


    在项目中动态添加了一个QComboBox,在当准备关联currentIndexChanged信号到某个成员函数中时,发现currentIndexChanged有两个重载:
        void currentIndexChanged(int index);
        void currentIndexChanged(const QString &);

    如果直接关联,例:

    connect(comboBox, &QComboBox::currentIndexChanged,this,  &Dialog::comBoxChangeIndex);

     会报:

    error: no matching member function for call to 'connect'
    需要把对应的函数强转一下,指定使用currentIndexChanged函数的那个重载:
    connect(comboBox, (void (QComboBox::*)(int))&QComboBox::currentIndexChanged, this, (void (Dialog::*)(int))&Dialog::comBoxChangeIndex);
    connect(comboBox, (void (QComboBox::*)(int))&QComboBox::currentIndexChanged, this, (void (Dialog::*)(int))&Dialog::comBoxChangeIndex);
    这样,就指定了要用QComboBox的currentIndexChanged(int)重载,如果想使用currentIndexChanged(const QString &)重载,把(void (QComboBox::*)(int))改成(void (QComboBox::*)(const QString &))


    例:
      connect(combobox, (void (QComboBox::*)(int))&QComboBox::currentIndexChanged, this, (void (Setting::*)(int))&Setting::typeComBoxCurrentIndexChanged);
      connect(combobox, (void (QComboBox::*)(const QString &))&QComboBox::currentIndexChanged, this, (void (Setting::*)(QString))&Setting::typeComBoxCurrentIndexChanged);

    这里Setting类的typeComBoxCurrentIndexChanged函数也有两个重载,对应QComboBox的currentIndexChanged函数两个重载。

    void typeComBoxCurrentIndexChanged(int)
    void typeComBoxCurrentIndexChanged(QString)
  • 相关阅读:
    Eclipse插件安装方法大全
    Weblogic web应用中获取文件的绝对路径
    Weblogic 设置优先引用web项目的jar包
    Oracle 数据库创建(图形界面操作)
    Java 输入输出流总结
    如何获取项目中文件的路径
    EclEmma安装与使用
    单向链表

    散列表
  • 原文地址:https://www.cnblogs.com/GengMingYan/p/15420626.html
Copyright © 2020-2023  润新知