<?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[Is it possible to add some behavior at the beginning of Qt-slot or before?]]></title><description><![CDATA[<p dir="auto">I use an auth form. Its implementation is not mine, so I cannot change it. The form has two fields for a login and password and also two buttons (ok + cancel).</p>
<p dir="auto">Let's imagine the <code>authorize</code> method looks like this (I replaced the code sending requests to a server with one condition inside the <code>if</code> statement):</p>
<pre><code>void AuthForm::on_btn_ok_clicked()
{
    if (loginLineEdit-&gt;text() == "auth" &amp;&amp; passwordLineEdit-&gt;text() == "auth")
        emit accepted();
    else
        emit rejected();
}
</code></pre>
<p dir="auto">I can connect to signals <code>AuthForm::accepted</code> or <code>AuthForm::rejected</code> to get result of authorization. But the problem is the default implementation of <code>AuthForm</code> does not validate form fields. Before the program send requests to authorize the user I want it to check if the form fields are empty or if the login match a mask.</p>
<p dir="auto">It works:</p>
<ol>
<li>user clicks <code>ok</code></li>
<li>calling of <code>on_btn_ok_clicked()</code> immediately</li>
<li>sending requests to get user logged in or not</li>
</ol>
<p dir="auto">I want it to work:</p>
<ol>
<li>user clicks <code>ok</code></li>
<li>verifying if the login match mask and check if the fields are not empty</li>
<li>using of default <code>on_btn_ok_clicked()</code> implementation</li>
</ol>
<p dir="auto">I think it should be like a middle layer between signal and slot. But I don't know if it is possible and how to do it.</p>
<p dir="auto">So, is it possible to add some behavior at the beginning of Qt-slot not modifying it?</p>
]]></description><link>https://forum.qt.io/topic/99142/is-it-possible-to-add-some-behavior-at-the-beginning-of-qt-slot-or-before</link><generator>RSS for Node</generator><lastBuildDate>Sun, 12 Apr 2026 00:40:17 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/99142.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 30 Jan 2019 12:17:02 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Is it possible to add some behavior at the beginning of Qt-slot or before? on Wed, 30 Jan 2019 21:27:24 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">Even shorter and just as clear:</p>
<pre><code>connect(ui-&gt;loginLineEdit,&amp;QLineEdit::textChanged,[this](const QString &amp;text)
   {
       QPushButton* okBut=ui-&gt;buttonBox-&gt;button(QDialogButtonBox::Ok);
       okBut-&gt;setDisabled(text.isEmpty());
   });
</code></pre>
]]></description><link>https://forum.qt.io/post/508444</link><guid isPermaLink="true">https://forum.qt.io/post/508444</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Wed, 30 Jan 2019 21:27:24 GMT</pubDate></item><item><title><![CDATA[Reply to Is it possible to add some behavior at the beginning of Qt-slot or before? on Wed, 30 Jan 2019 12:35:14 GMT]]></title><description><![CDATA[<p dir="auto">You can listen to textChanged signal of lineEdit and enable/disable the button accordingly:</p>
<pre><code>ui-&gt;setupUi(this);

   connect(ui-&gt;loginLineEdit,&amp;QLineEdit::textChanged,[this](const QString &amp;text)
       {
       QPushButton* okBut=ui-&gt;buttonBox-&gt;button(QDialogButtonBox::Ok);

       // button OK enabled if the field is not empty
       if(text.isEmpty())
           okBut-&gt;setEnabled(false);
       else
           okBut-&gt;setEnabled(true);

       });
</code></pre>
]]></description><link>https://forum.qt.io/post/508339</link><guid isPermaLink="true">https://forum.qt.io/post/508339</guid><dc:creator><![CDATA[mpergand]]></dc:creator><pubDate>Wed, 30 Jan 2019 12:35:14 GMT</pubDate></item><item><title><![CDATA[Reply to Is it possible to add some behavior at the beginning of Qt-slot or before? on Wed, 30 Jan 2019 12:20:56 GMT]]></title><description><![CDATA[<p dir="auto">You have to modify AuthForm to achieve what you want. How should it work otherwise? You don't have access to the ui elements outside AuthForm and even then you could not stop on_btn_ok_clicked() from being called without modifying the AuthForm code.</p>
]]></description><link>https://forum.qt.io/post/508334</link><guid isPermaLink="true">https://forum.qt.io/post/508334</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Wed, 30 Jan 2019 12:20:56 GMT</pubDate></item></channel></rss>