Skip to content

Support QList<T> even if T does not implement operator==() #1248

Open
@jnbooth

Description

@jnbooth

Some QLists in Qt have value types that do not implement equality. As specified in QList's documentation, if the value type of a QList does not implement ==, then the following functions are disabled:

  • contains
  • count
  • indexOf
  • lastIndexOf
  • !=
  • ==

Of those, we use contains and indexOf. One option here would be to have an additional trait for list element value types with equality, and then the QList implementation would use e.g.

    pub fn contains(&self, value: &T) -> bool
    where
        T: QListElementEq,
    {
        T::contains(self, value)
    }

At present, the workaround for the issue is to do something like this:

impl QListElement for MyType {
  fn contains(list: &QList<Self>, value: &Self) -> bool {
    false
  }

  fn index_of(list: &QList<Self>, value: &Self) -> isize {
    -1
  }
}

Obviously, that's not great.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions