<?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[(QDialog::DialogCode) QMessageBox.result() return enum value]]></title><description><![CDATA[<p dir="auto">So I have QMessageBox / QDialog::DialogCode to help with some dialogue pop-up confirmations. The method is written out like the following</p>
<pre><code>QDialog::DialogCode dialog_helper::confirm_clear_dialog()
{
     QMessageBox msgbox(QMessageBox::Icon::Question,"Confirm", "Are you sure you want to clear?");
        msgbox.addButton("No",QMessageBox::RejectRole);    
        msgbox.addButton("Yes",QMessageBox::AcceptRole);   
        msgbox.exec();    
        return (QDialog::DialogCode)msgbox.result();
}
void table_view_t::clearTableCommand()
{
    if(dialog_helper::confirm_clear_dialog() == QDialog::DialogCode::Accepted)
    {
        table_model-&gt;clear_clearTable();
    }
}
</code></pre>
<p dir="auto">In the past these methods seemed to work as expected, and accepting the dialogue would get past the dialog_helper::confirm_clear_dialog() == QDialog::DialogCode::Accepted comparison on older versions of QT. However, ever since we upgraded to QT 6.8.7, this interaction seems to be broken. Now the QMessageBox return value always seems to return an enum value of 3 and 4 for accepted and rejected but QDialog::DialogCode only contains 2 enum values (0 and 1) thus the comparison can never be true.</p>
<p dir="auto">I played around with it without much success but is there a simple refactor to fix this interaction, preferably on the helper method side. All of the other forums I've seen seem to parrot that this should work.</p>
<p dir="auto">Thank you</p>
]]></description><link>https://forum.qt.io/topic/164831/qdialog-dialogcode-qmessagebox.result-return-enum-value</link><generator>RSS for Node</generator><lastBuildDate>Mon, 29 Jun 2026 21:14:54 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/164831.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 29 Jun 2026 14:17:52 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to (QDialog::DialogCode) QMessageBox.result() return enum value on Mon, 29 Jun 2026 16:07:30 GMT]]></title><description><![CDATA[<p dir="auto">Please see the documentation at <a href="https://doc.qt.io/qt-6/qmessagebox.html#exec" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-6/qmessagebox.html#exec</a> , especially the note:</p>
<p dir="auto">"Note: The result() function returns also StandardButton value instead of QDialog::DialogCode."</p>
]]></description><link>https://forum.qt.io/post/838902</link><guid isPermaLink="true">https://forum.qt.io/post/838902</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Mon, 29 Jun 2026 16:07:30 GMT</pubDate></item><item><title><![CDATA[Reply to (QDialog::DialogCode) QMessageBox.result() return enum value on Mon, 29 Jun 2026 20:45:43 GMT]]></title><description><![CDATA[<p dir="auto">Thanks y'all, missed that piece of documentation this is what ended up working for me<br />
QDialog::DialogCode dialog_helper::confirm_clear_dialog()</p>
<p dir="auto">{<br />
QMessageBox msgbox(QMessageBox::Icon::Question,"Confirm", "Are you sure you want to clear?");<br />
msgbox.addButton("No",QMessageBox::NoRole);<br />
msgbox.addButton("Yes",QMessageBox::YesRole);<br />
msgbox.exec();</p>
<pre><code>switch (msgbox.result()) {
case QMessageBox::ActionRole:
    return QDialog::DialogCode::Accepted;
    break;
case QMessageBox::DestructiveRole:
default:
    return QDialog::DialogCode::Rejected;
    break;
}
</code></pre>
<p dir="auto">}</p>
]]></description><link>https://forum.qt.io/post/838910</link><guid isPermaLink="true">https://forum.qt.io/post/838910</guid><dc:creator><![CDATA[MilesM]]></dc:creator><pubDate>Mon, 29 Jun 2026 20:45:43 GMT</pubDate></item><item><title><![CDATA[Reply to (QDialog::DialogCode) QMessageBox.result() return enum value on Mon, 29 Jun 2026 16:11:20 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/milesm">@<bdi>MilesM</bdi></a><br />
I was just about to write same as <a class="plugin-mentions-user plugin-mentions-a" href="/user/christian-ehrlicher">@<bdi>Christian-Ehrlicher</bdi></a> has :)</p>
<p dir="auto">So in your helper just change <code>return (QDialog::DialogCode)msgbox.result();</code> to do an <code>if</code>/<code>switch</code> on the StandardButton values returning the appropriate DialogCode.</p>
]]></description><link>https://forum.qt.io/post/838903</link><guid isPermaLink="true">https://forum.qt.io/post/838903</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Mon, 29 Jun 2026 16:11:20 GMT</pubDate></item><item><title><![CDATA[Reply to (QDialog::DialogCode) QMessageBox.result() return enum value on Mon, 29 Jun 2026 16:07:30 GMT]]></title><description><![CDATA[<p dir="auto">Please see the documentation at <a href="https://doc.qt.io/qt-6/qmessagebox.html#exec" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-6/qmessagebox.html#exec</a> , especially the note:</p>
<p dir="auto">"Note: The result() function returns also StandardButton value instead of QDialog::DialogCode."</p>
]]></description><link>https://forum.qt.io/post/838902</link><guid isPermaLink="true">https://forum.qt.io/post/838902</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Mon, 29 Jun 2026 16:07:30 GMT</pubDate></item></channel></rss>