<?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[How to update QLineEdit in a QDialog]]></title><description><![CDATA[<p dir="auto">In the program that i'm developing, there is a QDialog class named BarramDialog that contains 4 QLineEdit Widgets and there is a class named Diagrama.</p>
<p dir="auto">barramdialog.h</p>
<pre><code class="language-c++">class BarramDialog;
}

class BarramDialog : public QDialog
{
    Q_OBJECT

public:
    explicit BarramDialog(QWidget *parent = nullptr);
    ~BarramDialog();
    QString nome="pegadinha";
    int num=42;
    float tensao;
    float ang;

    QString nome_dialog(QString &amp;);
    void setdata(QList&lt;QString&gt;&amp;);
    QList&lt;QString&gt; data=QList&lt;QString&gt;() &lt;&lt;""&lt;&lt;""&lt;&lt;""&lt;&lt;"";
</code></pre>
<p dir="auto">As you can see, in my class BarramDialog there is a QList&lt;QString&gt; variable that is responsible to set the text of the QLineEdit widgets when i execute the dialog:</p>
<p dir="auto">barramdialog.cpp</p>
<pre><code class="language-c++">BarramDialog::BarramDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::BarramDialog)
{
    ui-&gt;setupUi(this);

    ui-&gt;ang_lin-&gt;setText(data[0]);
    ui-&gt;tensao_line-&gt;setText(data[1]);
    ui-&gt;num_lin-&gt;setText(data[2]);
    ui-&gt;nome_lin-&gt;setText(data[3]);
    update();
}
</code></pre>
<p dir="auto">The problem is:</p>
<p dir="auto">diagrama.cpp</p>
<pre><code class="language-c++">void Diagrama::showMousePosition(const QPoint &amp;pos, const QVariant property)
{
    if(modo=="info")
    {

         BarramDialog *info=new BarramDialog;
         QList&lt;QString&gt; listagem= QList&lt;QString&gt;() &lt;&lt;QString::number(BarramentoMap[property.toString()]-&gt;ang)
                 &lt;&lt;QString::number(BarramentoMap[property.toString()]-&gt;tensao)
                 &lt;&lt;QString::number(BarramentoMap[property.toString()]-&gt;num)
                 &lt;&lt;BarramentoMap[property.toString()]-&gt;nome;
         info-&gt;setModal(true);
         info-&gt;setdata(listagem);


         info-&gt;exec();
    }
</code></pre>
<p dir="auto">the function setdata of BarramDialog is</p>
<pre><code>void BarramDialog::setdata(QList&lt;QString&gt; &amp;new_list)
{
   data=new_list;
}
</code></pre>
<p dir="auto">But when i use this function and execute the dialog, the text on QLineEdit widget stay the same.</p>
<p dir="auto">How can i fix it?</p>
]]></description><link>https://forum.qt.io/topic/102491/how-to-update-qlineedit-in-a-qdialog</link><generator>RSS for Node</generator><lastBuildDate>Tue, 07 Apr 2026 20:36:16 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/102491.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 06 May 2019 12:54:30 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to update QLineEdit in a QDialog on Tue, 07 May 2019 13:48:36 GMT]]></title><description><![CDATA[<p dir="auto">Thank you!!</p>
]]></description><link>https://forum.qt.io/post/527518</link><guid isPermaLink="true">https://forum.qt.io/post/527518</guid><dc:creator><![CDATA[frnklu20]]></dc:creator><pubDate>Tue, 07 May 2019 13:48:36 GMT</pubDate></item><item><title><![CDATA[Reply to How to update QLineEdit in a QDialog on Tue, 07 May 2019 04:50:46 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/gojir4">@<bdi>Gojir4</bdi></a> <a class="plugin-mentions-user plugin-mentions-a" href="/user/frnklu20">@<bdi>frnklu20</bdi></a> Actually there is no need for heap allocation of BarramDialog.</p>
<pre><code>void Diagrama::showMousePosition(const QPoint &amp;pos, const QVariant property)
{
    if(modo=="info")
    {
        BarramDialog info;
        ...
        info.exec();
    }
    ...
}
</code></pre>
]]></description><link>https://forum.qt.io/post/527396</link><guid isPermaLink="true">https://forum.qt.io/post/527396</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Tue, 07 May 2019 04:50:46 GMT</pubDate></item><item><title><![CDATA[Reply to How to update QLineEdit in a QDialog on Mon, 06 May 2019 13:19:00 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/frnklu20">@<bdi>frnklu20</bdi></a> Hi,</p>
<p dir="auto">Your QLineEdit are not updated because you don't update them in your method <code>setData</code>.</p>
<p dir="auto">I suggest to change <code>setData</code> like this:</p>
<pre><code>void BarramDialog::setdata(const QList&lt;QString&gt; &amp;new_list)
{
   ui-&gt;ang_lin-&gt;setText(data[0]);
   ui-&gt;tensao_line-&gt;setText(data[1]);
   ui-&gt;num_lin-&gt;setText(data[2]);
   ui-&gt;nome_lin-&gt;setText(data[3]);
}
</code></pre>
<p dir="auto">Other points:</p>
<ul>
<li>There is a memory leak issue in <code>showMousePosition()</code>. You have to set a parent to your dialog, or to destroy it at the end of the function:</li>
</ul>
<pre><code>BarramDialog *info=new BarramDialog(this);

//OR
BarramDialog *info=new BarramDialog;
...
info.deleteLater(); //put at the end of showMousePosition()
</code></pre>
<p dir="auto">Even simple, declare it on the stack:</p>
<pre><code>BarramDialog info;
...
info.exec()
</code></pre>
<ul>
<li>I have modified the parameter type in <code>setData</code> to <code>const QList&lt;QString&gt; &amp;new_list</code>. I have added the const directive as there is no reason to pass it by non-const reference.</li>
</ul>
]]></description><link>https://forum.qt.io/post/527303</link><guid isPermaLink="true">https://forum.qt.io/post/527303</guid><dc:creator><![CDATA[Gojir4]]></dc:creator><pubDate>Mon, 06 May 2019 13:19:00 GMT</pubDate></item><item><title><![CDATA[Reply to How to update QLineEdit in a QDialog on Mon, 06 May 2019 13:13:16 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/frnklu20">@<bdi>frnklu20</bdi></a> what about something like this (pseudo-code):</p>
<pre><code>BarramDialog::BarramDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::BarramDialog)
{
    ui-&gt;setupUi(this);
    updateLineEdits();
    ....
}

void BarramDialog::updateLineEdits()
{
     ui-&gt;ang_lin-&gt;setText(data[0]);
     ui-&gt;tensao_line-&gt;setText(data[1]);
     ui-&gt;num_lin-&gt;setText(data[2]);
     ui-&gt;nome_lin-&gt;setText(data[3]);
}

void BarramDialog::setdata(QList&lt;QString&gt; &amp;new_list)
{
   data=new_list;
   updateLineEdits();
}
</code></pre>
]]></description><link>https://forum.qt.io/post/527302</link><guid isPermaLink="true">https://forum.qt.io/post/527302</guid><dc:creator><![CDATA[Pablo J. Rogina]]></dc:creator><pubDate>Mon, 06 May 2019 13:13:16 GMT</pubDate></item></channel></rss>