-1

Pretty straightforward question.

QMap does not inherit QObject, so I'd like to know if there is an easy Qt Way of making it emit mySignal(MyEnum state).

If you are asking why I do not just emit a signal in my code when I call the function QMap::insert(...), its because this is done in a template... which """I think""" is impossible:

http://doc.qt.io/archives/qt-4.8/templates.html

If it helps, the QMap object I am using is global, and will be used between threads.

Anon
  • 2,267
  • 3
  • 34
  • 51
  • Just create in your app global extern(?) QObject for emit some signals and use this object when you need connect (queued connections for threads) or/and emit signals ( emit mySignalsObject.foo() ). – Deep Dec 05 '18 at 21:21

1 Answers1

1

It's easy:

class MyMap : public QObject
{
     Q_OBJECT;
public slots:
    void insert(... key, ... value)
    {
        _map.insert(key, value);
        emit isInserted(key);
    }
signals:
    void isInserted(... key);
private:
    QMap<..., ...> _map;
}
Alexander Chernin
  • 446
  • 2
  • 8
  • 17