mardi 15 septembre 2020

A static method as a method parameter (as a lambda)

I would like to have a constructor of class to have a lambda as a parameter:

class MyComboBox : public QComboBox
{
public:
 explicit QgsFlagCheckableComboBox<Flag>( std::function< QString( Flag ) > &readable, QWidget *parent = nullptr );
};

I have some flags in a class, which also have a static method:

class QgsField
{
  Q_GADGET
  public:
    enum class ConfigurationFlag : int
    {
      Searchable = 1 << 1,
      Readable = 1 << 2,
    };
    Q_ENUM( ConfigurationFlag )
    Q_DECLARE_FLAGS( ConfigurationFlags, ConfigurationFlag )
    Q_FLAG( ConfigurationFlags )

    static QString readableConfigurationFlag( QgsField::ConfigurationFlag flag );
};

I am trying to construct MyComboBox:

std::function<QString (QgsField::ConfigurationFlag)> readable = [](QgsField::ConfigurationFlag flag) {return QgsField::readableConfigurationFlag(flag);};
QComboBox *cb = new MyComboBox<QgsField::ConfigurationFlag>(readable, parent );

This fails:

Undefined symbols for architecture x86_64: "QgsFlagCheckableComboBoxQgsField::ConfigurationFlag::QgsFlagCheckableComboBox(std::__1::function<QString (QgsField::ConfigurationFlag)>&, QWidget*)

  1. Is there a way to pass the static method directly without going through a lambda (by definition the base class can change)?
  2. Why is it currently failing?

Aucun commentaire:

Enregistrer un commentaire