<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[qlabel not changing dynamically]]></title><description><![CDATA[<p dir="auto">I have a function (slot) where I try to set the text of a label after the label has already been created.</p>
<pre><code>void MyTab::editStuff(std::shared_ptr&lt;Stuff&gt; stuff)
{
    myLabel-&gt;setText(stuff-&gt;name());
}
</code></pre>
<p dir="auto">But it's not changing the label in my display. I plan on doing this often (user driven).</p>
<p dir="auto">What am I missing?</p>
]]></description><link>https://forum.qt.io/topic/122469/qlabel-not-changing-dynamically</link><generator>RSS for Node</generator><lastBuildDate>Tue, 14 Apr 2026 00:53:35 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/122469.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 08 Jan 2021 00:41:03 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to qlabel not changing dynamically on Mon, 11 Jan 2021 05:05:27 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/johnby">@<bdi>johnby</bdi></a> said in <a href="/post/637032">qlabel not changing dynamically</a>:</p>
<blockquote>
<p dir="auto">Yes, materlalLayout gets applied to the tab, and again, all this is fine. I have more widgets in that mix and they all show up. even materialLabel displays fine w/ whatever it's initialized with. It just doesn't update dynamically when my slot gets called and does a setText().</p>
</blockquote>
<p dir="auto">Please provide a minimal compilable example (including <code>main.cpp</code>) which contains this issue -- copy your project and remove the parts that are not involved with the issue. It is difficult to troubleshoot the code when bits are missing. For example, we can't see how <code>materialLayout</code> is applied to the tab, or where/when the connection is made.</p>
]]></description><link>https://forum.qt.io/post/637058</link><guid isPermaLink="true">https://forum.qt.io/post/637058</guid><dc:creator><![CDATA[JKSH]]></dc:creator><pubDate>Mon, 11 Jan 2021 05:05:27 GMT</pubDate></item><item><title><![CDATA[Reply to qlabel not changing dynamically on Mon, 11 Jan 2021 00:08:49 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/christian-ehrlicher">@<bdi>Christian-Ehrlicher</bdi></a> said in <a href="/post/636949">qlabel not changing dynamically</a>:</p>
<blockquote>
<p dir="auto">I still don't see where myLabel comes from and where you initialize it.</p>
</blockquote>
<p dir="auto">Ah, you're not looking at the latest post where things are renamed and I've given all the details. Forget anything prefixed w/ my.</p>
]]></description><link>https://forum.qt.io/post/637035</link><guid isPermaLink="true">https://forum.qt.io/post/637035</guid><dc:creator><![CDATA[johnby]]></dc:creator><pubDate>Mon, 11 Jan 2021 00:08:49 GMT</pubDate></item><item><title><![CDATA[Reply to qlabel not changing dynamically on Sun, 10 Jan 2021 23:36:31 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/chrisw67">@<bdi>ChrisW67</bdi></a> said in <a href="/post/636943">qlabel not changing dynamically</a>:</p>
<blockquote>
<p dir="auto">Is materialLayout applied to a widget?</p>
</blockquote>
<p dir="auto">Yes, materlalLayout gets applied to the tab, and again, all this is fine. I have more widgets in that mix and they all show up. even materialLabel displays fine w/ whatever it's initialized with. It just doesn't update dynamically when my slot gets called and does a setText().</p>
]]></description><link>https://forum.qt.io/post/637032</link><guid isPermaLink="true">https://forum.qt.io/post/637032</guid><dc:creator><![CDATA[johnby]]></dc:creator><pubDate>Sun, 10 Jan 2021 23:36:31 GMT</pubDate></item><item><title><![CDATA[Reply to qlabel not changing dynamically on Sun, 10 Jan 2021 08:30:39 GMT]]></title><description><![CDATA[<p dir="auto">I still don't see where myLabel comes from and where you initialize it.</p>
]]></description><link>https://forum.qt.io/post/636949</link><guid isPermaLink="true">https://forum.qt.io/post/636949</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Sun, 10 Jan 2021 08:30:39 GMT</pubDate></item><item><title><![CDATA[Reply to qlabel not changing dynamically on Sun, 10 Jan 2021 06:02:17 GMT]]></title><description><![CDATA[<p dir="auto">Is materialLayout applied to a widget?</p>
]]></description><link>https://forum.qt.io/post/636943</link><guid isPermaLink="true">https://forum.qt.io/post/636943</guid><dc:creator><![CDATA[ChrisW67]]></dc:creator><pubDate>Sun, 10 Jan 2021 06:02:17 GMT</pubDate></item><item><title><![CDATA[Reply to qlabel not changing dynamically on Sat, 09 Jan 2021 20:40:04 GMT]]></title><description><![CDATA[<p dir="auto">Ugh, forgot the other half there. I've updated that post to show the declaration of the QLabel in question.</p>
]]></description><link>https://forum.qt.io/post/636919</link><guid isPermaLink="true">https://forum.qt.io/post/636919</guid><dc:creator><![CDATA[johnby]]></dc:creator><pubDate>Sat, 09 Jan 2021 20:40:04 GMT</pubDate></item><item><title><![CDATA[Reply to qlabel not changing dynamically on Sat, 09 Jan 2021 19:05:51 GMT]]></title><description><![CDATA[<p dir="auto">Your code you show now don't use myLabel at all ...</p>
]]></description><link>https://forum.qt.io/post/636908</link><guid isPermaLink="true">https://forum.qt.io/post/636908</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Sat, 09 Jan 2021 19:05:51 GMT</pubDate></item><item><title><![CDATA[Reply to qlabel not changing dynamically on Sat, 09 Jan 2021 20:25:56 GMT]]></title><description><![CDATA[<p dir="auto">It's all C++ code, no designer work.<br />
Here's how I initialize the label and group in the ctor of my tab widget.</p>
<pre><code>class MaterialsTab : public QWidget
{
    Q_OBJECT
    
    private:
        QLabel *materialLabel;
        QVBoxLayout *materialLayout;
    
        // ...
    
    public:
        explicit MaterialsTab(QWidget *parent = 0);
    
    public slots:
        void editMaterial(const Material &amp;material);
}

MaterialsTab::MaterialsTab(QWidget *parent) : QWidget(parent)
{
    materialLabel = new QLabel();
    materialLabel-&gt;setVisible(true); // shouldn't need this, but tried anyway

    // ...

    materialLayout = new QVBoxLayout;

    // ...
    QGroupBox *nameGroup = new QGroupBox;

    QGridLayout *layout = new QGridLayout;
    layout-&gt;addWidget(materialLabel, 0, 1, 1, 3);
    // ...

    nameGroup-&gt;setLayout(layout);

    materialLayout-&gt;addWidget(nameGroup);
}
</code></pre>
]]></description><link>https://forum.qt.io/post/636906</link><guid isPermaLink="true">https://forum.qt.io/post/636906</guid><dc:creator><![CDATA[johnby]]></dc:creator><pubDate>Sat, 09 Jan 2021 20:25:56 GMT</pubDate></item><item><title><![CDATA[Reply to qlabel not changing dynamically on Sat, 09 Jan 2021 03:38:50 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/johnby">@<bdi>johnby</bdi></a> Is is possible that <code>myLabel</code> and the label that you see on screen are actually 2 different objects?</p>
<p dir="auto">Please show us how you initialized the QGroupBox and the QLabel. In particular:</p>
<ol>
<li>Did you use Qt Designer, or did you write pure C++ code?</li>
<li>How did you add your QLabel to the QGroupBox?</li>
</ol>
]]></description><link>https://forum.qt.io/post/636835</link><guid isPermaLink="true">https://forum.qt.io/post/636835</guid><dc:creator><![CDATA[JKSH]]></dc:creator><pubDate>Sat, 09 Jan 2021 03:38:50 GMT</pubDate></item><item><title><![CDATA[Reply to qlabel not changing dynamically on Sat, 09 Jan 2021 02:16:35 GMT]]></title><description><![CDATA[<p dir="auto">I definitely see the text that I'm expecting from the passed in parameter (const Material &amp;material) when printing to console.</p>
<p dir="auto">I even write ...</p>
<pre><code>materialLabel-&gt;setText("testing");
</code></pre>
<p dir="auto">and nothing changes in the tab.</p>
<p dir="auto"><strong>Update:</strong><br />
I just added</p>
<pre><code>qDebug() &lt;&lt; materialLabel-&gt;parentWidget() &lt;&lt; materialLabel-&gt;isVisible() &lt;&lt; materialLabel-&gt;pos();
</code></pre>
<p dir="auto">And got ...</p>
<pre><code>QGroupBox(0x558878be3740) false QPoint(0,0)
</code></pre>
<p dir="auto">It is in a QGroupBox, but the isVisible says false, so I added <code>setVisible(true)</code> to the QLabel, but nothing changed. I can see all qwidgets within the tab that I'm expecting to see, except for this label which is initialized as <code>new QLabel();</code> Which I believe means empty. I did initialize w/ a string and that of course displayed the label initialized with the string, but still, the value never updates dynamically when the slot is called.</p>
<p dir="auto">So, don't quite understand why the labels <code>isVisible</code> is showing false, because I can see it when I give it a string to init with.</p>
]]></description><link>https://forum.qt.io/post/636828</link><guid isPermaLink="true">https://forum.qt.io/post/636828</guid><dc:creator><![CDATA[johnby]]></dc:creator><pubDate>Sat, 09 Jan 2021 02:16:35 GMT</pubDate></item><item><title><![CDATA[Reply to qlabel not changing dynamically on Sat, 09 Jan 2021 01:51:53 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/johnby">@<bdi>johnby</bdi></a> said in <a href="/post/636825">qlabel not changing dynamically</a>:</p>
<blockquote>
<p dir="auto">It's just that the text is not changing.</p>
</blockquote>
<p dir="auto">What do you see when you debug your label?</p>
<pre><code>void MaterialsTab::editMaterial(const Material &amp;material)
{
    qDebug() &lt;&lt; myLabel-&gt;parentWidget() &lt;&lt; myLabel-&gt;isVisible() &lt;&lt; myLabel-&gt;pos()
    qDebug() &lt;&lt; myLabel-&gt;text();

    myLabel-&gt;setText("Hello");

    qDebug() &lt;&lt; myLabel-&gt;text();
}
</code></pre>
]]></description><link>https://forum.qt.io/post/636827</link><guid isPermaLink="true">https://forum.qt.io/post/636827</guid><dc:creator><![CDATA[JKSH]]></dc:creator><pubDate>Sat, 09 Jan 2021 01:51:53 GMT</pubDate></item><item><title><![CDATA[Reply to qlabel not changing dynamically on Sat, 09 Jan 2021 01:37:50 GMT]]></title><description><![CDATA[<p dir="auto">But that's what I mean when I said it works above when showing the signal/slot. The slot is definitely being called here ...</p>
<pre><code>void MaterialsTab::editMaterial(const Material &amp;material)
{
    myLabel-&gt;setText(material-&gt;name());
}
</code></pre>
<p dir="auto">It's just that the text is not changing. Also, once I get this working, I do plan on adding other fields to the Material class and having changes made, hence, not having <code>const</code> there.</p>
]]></description><link>https://forum.qt.io/post/636825</link><guid isPermaLink="true">https://forum.qt.io/post/636825</guid><dc:creator><![CDATA[johnby]]></dc:creator><pubDate>Sat, 09 Jan 2021 01:37:50 GMT</pubDate></item><item><title><![CDATA[Reply to qlabel not changing dynamically on Sat, 09 Jan 2021 00:54:23 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/johnby">@<bdi>johnby</bdi></a> said in <a href="/post/636817">qlabel not changing dynamically</a>:</p>
<blockquote>
<p dir="auto">Thoughts?</p>
</blockquote>
<p dir="auto">First, do some debugging to see which functions are called and which functions are not. You can use breakpoints or print debug messages.</p>
<p dir="auto">For example, put <code>qDebug()</code> inside your for-loop to check if the signal is even emitted:</p>
<pre><code>for (const auto&amp; material : *materials) { // NOTE: Use `const` since the variable won't be changed
	qDebug() &lt;&lt; "Checking" &lt;&lt; material.name();
	
	if (material.name() == name) { // NOTE: Just use `==`, don't need `compare()`
		qDebug() &lt;&lt; "Found it!";
		emit materialSelected(material);
		break;
	}
}
</code></pre>
]]></description><link>https://forum.qt.io/post/636821</link><guid isPermaLink="true">https://forum.qt.io/post/636821</guid><dc:creator><![CDATA[JKSH]]></dc:creator><pubDate>Sat, 09 Jan 2021 00:54:23 GMT</pubDate></item><item><title><![CDATA[Reply to qlabel not changing dynamically on Fri, 08 Jan 2021 23:33:35 GMT]]></title><description><![CDATA[<p dir="auto">I changed it back to a POD and made slot const, to no avail. But at least things are back to compiling. Here's more detail on what I'm doing.</p>
<p dir="auto">My goal is to have only one "material" tab on the display and when a user selects a material from a QTableView in another pane, then all the qlabels and other qwidgets within the tab will get set to the values of the selected "material" object that matches that name.</p>
<p dir="auto">What I do is have my user select a row in a QTableView which emits materialSelected() and calls the editMaterial() slot.</p>
<pre><code>connect(qobject_cast&lt;MaterialsProperties*&gt;(materials),
    &amp;MaterialsProperties::materialSelected,
    qobject_cast&lt;MaterialsTab*&gt;(tabMaterials),
    &amp;MaterialsTab::editMaterial);
</code></pre>
<p dir="auto">This works.<br />
Next is the signal/slot where I try to set the text of a label after the label has already been created.</p>
<pre><code>void MaterialsProperties::changeTab(const QString &amp;name)
{   
    for (auto&amp; material : *materials) {
        if (material.name().compare(name) == 0) {
            emit materialSelected(material);

            break;
        }
    }

    mainWin-&gt;showMainViewTabByName(MATERIALS);
}   

void MaterialsTab::editMaterial(const Material &amp;material)
{
    myLabel-&gt;setText(material-&gt;name());
}
</code></pre>
<p dir="auto">But it's not changing the label in the display. Class Material is defined as a POD as follows.</p>
<pre><code>class Material
{
    private:
        QString materialName;
    
    public:
        Material(const QString &amp;name);
    
        QString name() const;
};
</code></pre>
<p dir="auto">Thoughts?</p>
]]></description><link>https://forum.qt.io/post/636817</link><guid isPermaLink="true">https://forum.qt.io/post/636817</guid><dc:creator><![CDATA[johnby]]></dc:creator><pubDate>Fri, 08 Jan 2021 23:33:35 GMT</pubDate></item><item><title><![CDATA[Reply to qlabel not changing dynamically on Fri, 08 Jan 2021 08:58:55 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/kent-dorfman">@<bdi>Kent-Dorfman</bdi></a> said in <a href="/post/636552">qlabel not changing dynamically</a>:</p>
<blockquote>
<p dir="auto">Unless I'm mistaken the above won't work unless the Stuff class is registered with the metadata system.  Is that not true?</p>
</blockquote>
<p dir="auto">You only need to register if you want a Queued connection. Direct connections don't need registration.</p>
]]></description><link>https://forum.qt.io/post/636583</link><guid isPermaLink="true">https://forum.qt.io/post/636583</guid><dc:creator><![CDATA[JKSH]]></dc:creator><pubDate>Fri, 08 Jan 2021 08:58:55 GMT</pubDate></item><item><title><![CDATA[Reply to qlabel not changing dynamically on Fri, 08 Jan 2021 06:53:05 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jksh">@<bdi>JKSH</bdi></a> said in <a href="/post/636536">qlabel not changing dynamically</a>:</p>
<blockquote>
<p dir="auto">and make your slot void MyTab::editStuff(const Stuff &amp;stuff)</p>
</blockquote>
<p dir="auto">Unless I'm mistaken the above won't work unless the Stuff class is registered with the metadata system.  Is that not true?  I'm sure I read somewhere years ago that the slot parameter types needed to be registered with the framework?  Not true?</p>
<p dir="auto">Is <strong>Q_DECLARE_METATYPE(type)</strong> not required any more?  Shows how frequently I pass class types. LOL</p>
]]></description><link>https://forum.qt.io/post/636552</link><guid isPermaLink="true">https://forum.qt.io/post/636552</guid><dc:creator><![CDATA[Kent-Dorfman]]></dc:creator><pubDate>Fri, 08 Jan 2021 06:53:05 GMT</pubDate></item><item><title><![CDATA[Reply to qlabel not changing dynamically on Fri, 08 Jan 2021 04:35:11 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/johnby">@<bdi>johnby</bdi></a> said in <a href="/post/636531">qlabel not changing dynamically</a>:</p>
<blockquote>
<p dir="auto">I've changed class Stuff to be derived from QObject, was a POD.</p>
</blockquote>
<p dir="auto">May I ask why?</p>
<p dir="auto">See <a href="https://doc.qt.io/qt-5/object.html#qt-objects-identity-vs-value" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-5/object.html#qt-objects-identity-vs-value</a> -- Think of QObjects as "identities". If your class represents data instead of an identity, there is no reason to inherit QObject.</p>
<blockquote>
<pre><code>/usr/include/qt5/QtCore/qlist.h:465:65: error: use of deleted function ‘Stuff::Stuff(const Stuff&amp;)’
</code></pre>
</blockquote>
<p dir="auto">To enforce the idea that QObjects are Identity objects, the QObject copy constructor is deleted. This means they QObjects cannot be copied, and that's why your compiler won't let you store QObjects in a <code>QList</code> (or any other container)</p>
<p dir="auto">To solve your original problem, a typical approach is to make your class POD again, and make your slot <code>void MyTab::editStuff(const Stuff &amp;stuff)</code></p>
<p dir="auto">If you want different suggestions, please provide more details about how you've structured your code. (For example: What is the relationship between <code>Stuff</code> and <code>MyTab</code>? Where do you store your <code>Stuff</code>?)</p>
]]></description><link>https://forum.qt.io/post/636536</link><guid isPermaLink="true">https://forum.qt.io/post/636536</guid><dc:creator><![CDATA[JKSH]]></dc:creator><pubDate>Fri, 08 Jan 2021 04:35:11 GMT</pubDate></item><item><title><![CDATA[Reply to qlabel not changing dynamically on Fri, 08 Jan 2021 03:38:44 GMT]]></title><description><![CDATA[<p dir="auto">I've changed class Stuff to be derived from QObject, was a POD.</p>
<pre><code>class Stuff : QObject
{
    Q_OBJECT

    private:

        QString name;
    
    public:
        Stuff(const QString &amp;name);
        
        QString name() const;
};      
</code></pre>
<p dir="auto">But now I can't seem to get past this error ...</p>
<pre><code>stuff-model.cpp:55:27:   required from here 
/usr/include/qt5/QtCore/qlist.h:465:65: error: use of deleted function ‘Stuff::Stuff(const Stuff&amp;)’
  465 |     if (QTypeInfo&lt;T&gt;::isLarge || QTypeInfo&lt;T&gt;::isStatic) n-&gt;v = new T(t);                                                                               
  |                                                                 ^~~~~~~~In file included from stuff-
model.h:6,                                                                                       from stuff-model.
cpp:3:                                                                          ../../../../stuff.h:6:7: note: ‘Stuff:
:Stuff(const Stuff&amp;)’ is implicitly deleted because the default definition would be ill-formed:       
6 | class Stuff : QObject                                                
  |       ^~~~~~~~                                                          
stuff.h:6:7: error: use of deleted function ‘QObject::QObject(const QObject&amp;)’
In file included from /usr/include/qt5/QtCore/qatomic.h:41,         
             from /usr/include/qt5/QtCore/qvariant.h:43,       
             from /usr/include/qt5/QtCore/qabstractitemmodel.h:43,
             from /usr/include/qt5/QtCore/QAbstractTableModel:1,                             
from stuff-model.h:3,                                                                      
             from stuff-model.cpp:3:
/usr/include/qt5/QtCore/qobject.h:467:20: note: declared here             
  467 |     Q_DISABLE_COPY(QObject)                                             
  |                    ^~~~~~~                                              
/usr/include/qt5/QtCore/qglobal.h:435:5: note: in definition of macro ‘Q_DISABLE
_COPY’                                                                          
  435 |     Class(const Class &amp;) = delete;\
  |     ^~~~~
</code></pre>
<p dir="auto">I'm thinking it's that last line ...</p>
<pre><code>Class(const Class &amp;) = delete;
</code></pre>
<p dir="auto">But not sure how to handle this now that I'm having to derive from QObject.</p>
]]></description><link>https://forum.qt.io/post/636531</link><guid isPermaLink="true">https://forum.qt.io/post/636531</guid><dc:creator><![CDATA[johnby]]></dc:creator><pubDate>Fri, 08 Jan 2021 03:38:44 GMT</pubDate></item><item><title><![CDATA[Reply to qlabel not changing dynamically on Fri, 08 Jan 2021 01:17:14 GMT]]></title><description><![CDATA[<p dir="auto">Don't mix std::shared_ptr into slots.  Therein lies madness.</p>
<p dir="auto">Passing data into a slot isn't as flexible as you're trying to make it.  Only pass types that have been registered with the metaobject system.  Best to stick with Qt derived types or basic ordinal types.</p>
<pre><code>MySlot(Qstring&amp; str) {
    myLabel-&gt;setText(str);
}
</code></pre>
]]></description><link>https://forum.qt.io/post/636518</link><guid isPermaLink="true">https://forum.qt.io/post/636518</guid><dc:creator><![CDATA[Kent-Dorfman]]></dc:creator><pubDate>Fri, 08 Jan 2021 01:17:14 GMT</pubDate></item></channel></rss>