Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't think that's a good idea. You are wrapping every float of your hash with a QObject which sounds very heavy to me.</p> <p>You can hap the whole HashMap inside the QObject and emit the signal from there when the value you are interested in has changed.</p> <pre><code>class MyHashMap : public QObject { Q_OBJECT public: explicit MyHashMap(QObject *parent = 0); float Get(const QString&amp; key) const; void SetValue(const QString&amp; key, float value) { // only emit value changed if the value has actually changed QHashMap&lt;QString, float&gt;::iterator it = myHashMap.find(key); if(it != myHashMap.end()){ if(it.value != value){ myHashMap[key] = value; emit ValueChanged(key, value); } } } private: QHashMap&lt;QString, float&gt; myHashMap; signals: void ValueChanged(const QString&amp; key, float newValue); }; </code></pre> <p>According to your comment, you want to update a label when a value has changed. Simply add all the labels to a QHashMap, then connect the ValueChanged signal to a slot that updates the right label:</p> <pre><code>class MyWidget : public QWidget { Q_OBJECT public: explicit MyWidget(QWidget *parent = 0) { ... ... myLabels["label1"] = myLabel1; myLabels["label2"] = myLabel2; QObject::connect(myLabels, SIGNAL(ValueChanged(const QString&amp;, float)), this, OnValueChanged(const QString&amp;, float)); } public slots: void OnValueChanged(const QString&amp; key, float newValue){ QHashMap&lt;QString, QLabel*&gt;::iterator it = myLabels.find(key); if(it != myLabels.end()){ it.value()-&gt;setText(QString::number(newValue)); } } private: QHashMap&lt;QString, QLabel*&gt; myLabels; }; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload