Qt: How to subtract two QSet QString in deadband mode

I am working on a logical problem using Qt. I have two QSets QString:

QSet<QString> set1: [ "aaa", "BBB" ]
QSet<QString> set2: [ "aaa", "bbb", "ccc", "ddd" ]

I want to subtract set1 from set2, so I use:

set2.subtract( set1 );

And I get:

set2: ["bbb", "ccc", "ddd"]

But in this case, "bbb" is not removed from set2, although set1 contains this entry. This is because the default QString :: contains method (this is the method used by QSet :: subtract) is case sensitive.

There is another QString :: contains method that takes a parameter to determine the case sensitivity mode, but I really don't see how I can use it.

Does anyone have an idea how to do case insensitive subtraction between two QSet QString, please?

Here is what I have tried so far:

set2 , , ( ).

QSet . MyStringSet, Qt, . p >

+3
2

Qt STL. std:: set_difference . , :

struct qstring_compare_i
{
    bool operator()(const QString & x, const QString y) const
    { return QString::compare(x, y, Qt::CaseInsensitive) < 0; }
};

static QSet<QString> substract_sets(const QSet<QString> & qs1, const QSet<QString> & qs2)
{
    std::set<QString> r;
    std::set_difference(qs1.begin(), qs1.end(), qs2.begin(), qs2.end(), std::inserter(r, r.end()), qstring_compare_i());

    QSet<QString> result;
    for(std::set<QString>::iterator i=r.begin();i!=r.end();++i) {
        result << *i;
    }
    return result;
}
+8

- QString, , , :

  class QStringInsensitive: public QString
  {
     bool operator==(const QString& other) const
     {
        return (0 == this->compare(other, Qt::CaseInsensitive));
     }
  };
  QSet< QStringInsensitive > set;
+3

All Articles