简体   繁体   中英

How can I make a QMap object emit a signal when `QMap::insert(…)` is called?

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.

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM