<?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[Change Label on MainWindow not working]]></title><description><![CDATA[<p dir="auto">Hello guys,</p>
<p dir="auto">I am running out of ideas with my problem. I have a simple gui that creates a simple test form, on that test form I want to press a button and change a label on the MainWindow. Please look at my code:</p>
<p dir="auto">Testform.cpp</p>
<pre><code>#include "testform.h"
#include "ui_testform.h"

TestForm::TestForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::TestForm)
{
    ui-&gt;setupUi(this);
    this-&gt;mw = new MainWindow();
    connect(ui-&gt;pB_ChangeLabelOnMainForm, &amp;QPushButton::clicked, this-&gt;mw, &amp;MainWindow::changeLabelOnUi);
}

TestForm::~TestForm()
{
    delete ui;
}

</code></pre>
<p dir="auto">Testform.h</p>
<pre><code>#ifndef TESTFORM_H
#define TESTFORM_H

#include "mainwindow.h"
#include &lt;QWidget&gt;

namespace Ui {
class TestForm;
}

class TestForm : public QWidget
{
    Q_OBJECT

public:
    explicit TestForm(QWidget *parent = nullptr);
    ~TestForm();

private:
    Ui::TestForm *ui;
    MainWindow *mw;

};

#endif // TESTFORM_H

</code></pre>
<p dir="auto">mainwindow.cpp</p>
<pre><code>#include "mainwindow.h"
#include "testform.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui-&gt;setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pB_OpenDialog_clicked()
{
    TestForm *tf = new TestForm();
    tf-&gt;show();
}

//+++ HERE IS MY PROBLEM+++
void MainWindow::changeLabelOnUi()
{
    this-&gt;ui-&gt;lblToChangeOnMF-&gt;setText("Hello"); // NOT WORKING
    qDebug() &lt;&lt; "TESTOUTPUT"; // WORKING
}


</code></pre>
<p dir="auto">mainwindow.h</p>
<pre><code>#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include &lt;QMainWindow&gt;

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private slots:
    void on_pB_OpenDialog_clicked();

public slots:
    void changeLabelOnUi();

private:
    Ui::MainWindow *ui;

};
#endif // MAINWINDOW_H

</code></pre>
<p dir="auto">Can someone tell me why the label-change-code in the function changeLabelOnUi() in the mainwindow.cpp is not working but the qDebug() line does? When I call this function for example in the constructor, the label has changed.</p>
<p dir="auto">I have tried another example in that the MainForm is the sender and I have changed a label on the TestForm, here was everything fine.</p>
<p dir="auto">Thank you! :-)</p>
]]></description><link>https://forum.qt.io/topic/142103/change-label-on-mainwindow-not-working</link><generator>RSS for Node</generator><lastBuildDate>Wed, 12 Aug 2026 15:15:59 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/142103.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 10 Jan 2023 17:39:02 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Change Label on MainWindow not working on Tue, 10 Jan 2023 20:02:28 GMT]]></title><description><![CDATA[<p dir="auto">omfg... it was that simple O_O</p>
<p dir="auto">Thank you very much!!!! :-)</p>
]]></description><link>https://forum.qt.io/post/743356</link><guid isPermaLink="true">https://forum.qt.io/post/743356</guid><dc:creator><![CDATA[buzz_lightzyear]]></dc:creator><pubDate>Tue, 10 Jan 2023 20:02:28 GMT</pubDate></item><item><title><![CDATA[Reply to Change Label on MainWindow not working on Tue, 10 Jan 2023 18:31:08 GMT]]></title><description><![CDATA[<p dir="auto">The easy way is to use modal dialog:</p>
<pre><code>void MainWindow::on_pB_OpenDialog_clicked()
{
    TestForm tf = TestForm();
    if(tf-&gt;exec()==QDialog::Accepted)
        {
        // update data here
        }
}
</code></pre>
]]></description><link>https://forum.qt.io/post/743336</link><guid isPermaLink="true">https://forum.qt.io/post/743336</guid><dc:creator><![CDATA[mpergand]]></dc:creator><pubDate>Tue, 10 Jan 2023 18:31:08 GMT</pubDate></item><item><title><![CDATA[Reply to Change Label on MainWindow not working on Tue, 10 Jan 2023 18:17:41 GMT]]></title><description><![CDATA[<p dir="auto">The code exampe is - of course - only an abstract demonstration of my problem. In that program I want to develop I want to open a dialog window, enter some data, with the ok-Button the data is stored into a database, on the cancel button nothing happens. And: With the click on the ok-button the list view on the main window should get updated.</p>
<p dir="auto">Now I do that with a update button, but for the next version of my program I want to remove that button and the update of the list view should happen automatically.</p>
]]></description><link>https://forum.qt.io/post/743331</link><guid isPermaLink="true">https://forum.qt.io/post/743331</guid><dc:creator><![CDATA[buzz_lightzyear]]></dc:creator><pubDate>Tue, 10 Jan 2023 18:17:41 GMT</pubDate></item><item><title><![CDATA[Reply to Change Label on MainWindow not working on Tue, 10 Jan 2023 18:10:13 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/buzz_lightzyear">@<bdi>buzz_lightzyear</bdi></a> said in <a href="/post/743324">Change Label on MainWindow not working</a>:</p>
<blockquote>
<p dir="auto">But how do I get to "that" Main Form I need? With a Singleton? Or are there other ways?</p>
</blockquote>
<p dir="auto">Explain what you want to do exactly.</p>
]]></description><link>https://forum.qt.io/post/743329</link><guid isPermaLink="true">https://forum.qt.io/post/743329</guid><dc:creator><![CDATA[mpergand]]></dc:creator><pubDate>Tue, 10 Jan 2023 18:10:13 GMT</pubDate></item><item><title><![CDATA[Reply to Change Label on MainWindow not working on Tue, 10 Jan 2023 18:03:37 GMT]]></title><description><![CDATA[<p dir="auto">omg... thank you. I think I now see the problem... I was wrong all the time. And the qDebug() - Output comes from that other form, but nothing changes on my main form.</p>
<p dir="auto">But how do I get to "that" Main Form I need? With a Singleton? Or are there other ways?</p>
<p dir="auto">Thank you in advance!</p>
]]></description><link>https://forum.qt.io/post/743324</link><guid isPermaLink="true">https://forum.qt.io/post/743324</guid><dc:creator><![CDATA[buzz_lightzyear]]></dc:creator><pubDate>Tue, 10 Jan 2023 18:03:37 GMT</pubDate></item><item><title><![CDATA[Reply to Change Label on MainWindow not working on Tue, 10 Jan 2023 17:58:35 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/buzz_lightzyear">@<bdi>buzz_lightzyear</bdi></a><br />
I guess the windows are not the same.</p>
<pre><code>void MainWindow::on_pB_OpenDialog_clicked()
{
    TestForm *tf = new TestForm();
    tf-&gt;show();
}
</code></pre>
<p dir="auto">Here you create a TestForm that in turn create a new Window , strange !</p>
]]></description><link>https://forum.qt.io/post/743322</link><guid isPermaLink="true">https://forum.qt.io/post/743322</guid><dc:creator><![CDATA[mpergand]]></dc:creator><pubDate>Tue, 10 Jan 2023 17:58:35 GMT</pubDate></item></channel></rss>