<?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[Message handler, fflush(stderr) doesn&#x27;t work]]></title><description><![CDATA[<p dir="auto">I have a message handler:</p>
<pre><code>void qDebugMsgHandler(QtMsgType type, const QMessageLogContext&amp; context, const QString&amp; strMsg) {
    QString strOutput;

    if ( context.file ) {
        strOutput += QString(context.file);

        if ( context.function ) {
            if ( context.line &gt; 0 ) {
                strOutput += QString(" L%1").arg(context.line, 8, 10, QChar('0')) + QString(":");
            }
            strOutput += QString(context.function);
        }
    }
    if ( strMsg.length() &gt; 0 ) {
        if ( strOutput.length() &gt; 0 ) {
            strOutput += ": ";
        }
        strOutput += strMsg;
    }
    switch( type ) {
    case QtDebugMsg:
        fprintf(stderr, "   Debug:%s\n", strOutput.toLatin1().data());
        break;
    case QtInfoMsg:
        fprintf(stderr, "    Info:%s\n", strOutput.toLatin1().data());
        break;
    case QtWarningMsg:
        fprintf(stderr, " Warning:%s\n", strOutput.toLatin1().data());
        break;
    case QtCriticalMsg:
        fprintf(stderr, "Critical:%s\n", strOutput.toLatin1().data());
        break;
    case QtFatalMsg:
        fprintf(stderr, "   Fatal:%s\n", strOutput.toLatin1().data());
        break;
    }
    fflush(stderr);
}
</code></pre>
<p dir="auto">This is installed when my application starts:</p>
<pre><code>int main(int argc, char *argv[]) {
    if ( argc &lt; 2 ) {
        error(static_cast&lt;const char*&gt;("Please specify configuration file!"));
   }
    QString strConfig = QString(argv[1]);
    //Install custom message handler
    qInstallMessageHandler(qDebugMsgHandler);
</code></pre>
<p dir="auto">Although every call to this handler ends with a flush(stderr), there are times when I know calls to qDebug has been called but I do not see anything in the Application Output, sometimes for a very long time.</p>
<p dir="auto">It seems that the call to fflush isn't enough ?</p>
]]></description><link>https://forum.qt.io/topic/117034/message-handler-fflush-stderr-doesn-t-work</link><generator>RSS for Node</generator><lastBuildDate>Thu, 17 Sep 2026 11:14:07 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/117034.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 15 Jul 2020 08:42:59 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Message handler, fflush(stderr) doesn&#x27;t work on Thu, 16 Jul 2020 11:01:14 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/splatten">@<bdi>SPlatten</bdi></a><br />
Ok, im not sure what causes this but its worth a shot.</p>
]]></description><link>https://forum.qt.io/post/607191</link><guid isPermaLink="true">https://forum.qt.io/post/607191</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Thu, 16 Jul 2020 11:01:14 GMT</pubDate></item><item><title><![CDATA[Reply to Message handler, fflush(stderr) doesn&#x27;t work on Thu, 16 Jul 2020 10:59:12 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/splatten">@<bdi>SPlatten</bdi></a>, In the message handler, I'm going to push every entry onto a stack then have a separate thread that services the stack popping off the first from the stack.</p>
]]></description><link>https://forum.qt.io/post/607189</link><guid isPermaLink="true">https://forum.qt.io/post/607189</guid><dc:creator><![CDATA[SPlatten]]></dc:creator><pubDate>Thu, 16 Jul 2020 10:59:12 GMT</pubDate></item><item><title><![CDATA[Reply to Message handler, fflush(stderr) doesn&#x27;t work on Thu, 16 Jul 2020 10:21:01 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a> , ok, now I'm really confused, after adding my API routine, I can now see using the debugger than messages from JavaScript via the API call and C++ make it into the message handler, I' ve stepped through and the output string contains correct content, but for some reason I do not see the output from the JavaScript API call in the Application Output.</p>
]]></description><link>https://forum.qt.io/post/607181</link><guid isPermaLink="true">https://forum.qt.io/post/607181</guid><dc:creator><![CDATA[SPlatten]]></dc:creator><pubDate>Thu, 16 Jul 2020 10:21:01 GMT</pubDate></item><item><title><![CDATA[Reply to Message handler, fflush(stderr) doesn&#x27;t work on Thu, 16 Jul 2020 09:50:46 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a> , in the end I wrote a routine in the C++ that is invokable in the JavaScript, then just replaced all calls to <a href="http://console.info" target="_blank" rel="noopener noreferrer nofollow ugc">console.info</a> with my own routine, this works well.</p>
]]></description><link>https://forum.qt.io/post/607173</link><guid isPermaLink="true">https://forum.qt.io/post/607173</guid><dc:creator><![CDATA[SPlatten]]></dc:creator><pubDate>Thu, 16 Jul 2020 09:50:46 GMT</pubDate></item><item><title><![CDATA[Reply to Message handler, fflush(stderr) doesn&#x27;t work on Wed, 15 Jul 2020 12:01:33 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/splatten">@<bdi>SPlatten</bdi></a><br />
Good found.<br />
Yes seem so.<br />
I would try it at once as no harm from it.</p>
]]></description><link>https://forum.qt.io/post/606961</link><guid isPermaLink="true">https://forum.qt.io/post/606961</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Wed, 15 Jul 2020 12:01:33 GMT</pubDate></item><item><title><![CDATA[Reply to Message handler, fflush(stderr) doesn&#x27;t work on Wed, 15 Jul 2020 10:48:35 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a> , found this, <a href="https://stackoverflow.com/questions/28412477/how-to-flush-console-log-output-on-windows" target="_blank" rel="noopener noreferrer nofollow ugc">https://stackoverflow.com/questions/28412477/how-to-flush-console-log-output-on-windows</a></p>
<p dir="auto">Couldn't I just flush stdout too?</p>
]]></description><link>https://forum.qt.io/post/606938</link><guid isPermaLink="true">https://forum.qt.io/post/606938</guid><dc:creator><![CDATA[SPlatten]]></dc:creator><pubDate>Wed, 15 Jul 2020 10:48:35 GMT</pubDate></item><item><title><![CDATA[Reply to Message handler, fflush(stderr) doesn&#x27;t work on Wed, 15 Jul 2020 10:43:54 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/splatten">@<bdi>SPlatten</bdi></a><br />
Ok then i understand it.<br />
Im not sure how to flush its buffers then.<br />
JS dont have a flush on its own or anything?</p>
]]></description><link>https://forum.qt.io/post/606936</link><guid isPermaLink="true">https://forum.qt.io/post/606936</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Wed, 15 Jul 2020 10:43:54 GMT</pubDate></item><item><title><![CDATA[Reply to Message handler, fflush(stderr) doesn&#x27;t work on Wed, 15 Jul 2020 10:29:16 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a> , sorry, this application is only JS.</p>
]]></description><link>https://forum.qt.io/post/606925</link><guid isPermaLink="true">https://forum.qt.io/post/606925</guid><dc:creator><![CDATA[SPlatten]]></dc:creator><pubDate>Wed, 15 Jul 2020 10:29:16 GMT</pubDate></item><item><title><![CDATA[Reply to Message handler, fflush(stderr) doesn&#x27;t work on Wed, 15 Jul 2020 10:26:54 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/splatten">@<bdi>SPlatten</bdi></a><br />
So yes to QML?</p>
]]></description><link>https://forum.qt.io/post/606920</link><guid isPermaLink="true">https://forum.qt.io/post/606920</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Wed, 15 Jul 2020 10:26:54 GMT</pubDate></item><item><title><![CDATA[Reply to Message handler, fflush(stderr) doesn&#x27;t work on Wed, 15 Jul 2020 10:26:30 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a>, <a href="http://console.info" target="_blank" rel="noopener noreferrer nofollow ugc">console.info</a></p>
]]></description><link>https://forum.qt.io/post/606918</link><guid isPermaLink="true">https://forum.qt.io/post/606918</guid><dc:creator><![CDATA[SPlatten]]></dc:creator><pubDate>Wed, 15 Jul 2020 10:26:30 GMT</pubDate></item><item><title><![CDATA[Reply to Message handler, fflush(stderr) doesn&#x27;t work on Wed, 15 Jul 2020 10:24:16 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/splatten">@<bdi>SPlatten</bdi></a><br />
Im not sure what is being used internally.<br />
<a href="https://doc.qt.io/qt-5/qtquick-debugging.html" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-5/qtquick-debugging.html</a><br />
sounds like it is using qDebug. internally.<br />
but is this console.log in QML or pure JS ?</p>
]]></description><link>https://forum.qt.io/post/606915</link><guid isPermaLink="true">https://forum.qt.io/post/606915</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Wed, 15 Jul 2020 10:24:16 GMT</pubDate></item><item><title><![CDATA[Reply to Message handler, fflush(stderr) doesn&#x27;t work on Wed, 15 Jul 2020 10:18:23 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a> One possible solution could be to redirect stdout to stderr ?</p>
]]></description><link>https://forum.qt.io/post/606911</link><guid isPermaLink="true">https://forum.qt.io/post/606911</guid><dc:creator><![CDATA[SPlatten]]></dc:creator><pubDate>Wed, 15 Jul 2020 10:18:23 GMT</pubDate></item><item><title><![CDATA[Reply to Message handler, fflush(stderr) doesn&#x27;t work on Wed, 15 Jul 2020 09:36:58 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/splatten">@<bdi>SPlatten</bdi></a><br />
ahh that way :)<br />
Nope i would assume its something else since its on JS side.</p>
]]></description><link>https://forum.qt.io/post/606891</link><guid isPermaLink="true">https://forum.qt.io/post/606891</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Wed, 15 Jul 2020 09:36:58 GMT</pubDate></item><item><title><![CDATA[Reply to Message handler, fflush(stderr) doesn&#x27;t work on Wed, 15 Jul 2020 09:09:04 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a>, sorry, my fault, it won't do anything because although the output appears eventually in the Application Output, the function that is called to do the output is not qDebug().  The output is produced in Script using "<a href="http://console.info" target="_blank" rel="noopener noreferrer nofollow ugc">console.info</a>", which although it appears in the Application Output obviously doesn't go via the same handlers that the qDebug() does.</p>
]]></description><link>https://forum.qt.io/post/606872</link><guid isPermaLink="true">https://forum.qt.io/post/606872</guid><dc:creator><![CDATA[SPlatten]]></dc:creator><pubDate>Wed, 15 Jul 2020 09:09:04 GMT</pubDate></item><item><title><![CDATA[Reply to Message handler, fflush(stderr) doesn&#x27;t work on Wed, 15 Jul 2020 09:00:20 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/splatten">@<bdi>SPlatten</bdi></a><br />
Ok. normally its due to std etc is being buffered but<br />
seems not to be the case here then.<br />
and you did set a break point to verify it is indeed called ?</p>
]]></description><link>https://forum.qt.io/post/606866</link><guid isPermaLink="true">https://forum.qt.io/post/606866</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Wed, 15 Jul 2020 09:00:20 GMT</pubDate></item><item><title><![CDATA[Reply to Message handler, fflush(stderr) doesn&#x27;t work on Wed, 15 Jul 2020 08:53:50 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a> , thanks, just tried, no difference.</p>
]]></description><link>https://forum.qt.io/post/606863</link><guid isPermaLink="true">https://forum.qt.io/post/606863</guid><dc:creator><![CDATA[SPlatten]]></dc:creator><pubDate>Wed, 15 Jul 2020 08:53:50 GMT</pubDate></item><item><title><![CDATA[Reply to Message handler, fflush(stderr) doesn&#x27;t work on Wed, 15 Jul 2020 08:51:55 GMT]]></title><description><![CDATA[<p dir="auto">Hi<br />
Could you try with<br />
setbuf(stderr, nullptr)<br />
in main.cpp before anything else and see if that makes a difference?</p>
]]></description><link>https://forum.qt.io/post/606862</link><guid isPermaLink="true">https://forum.qt.io/post/606862</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Wed, 15 Jul 2020 08:51:55 GMT</pubDate></item></channel></rss>