<?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[Log Window Not Showing!]]></title><description><![CDATA[<p dir="auto">Hi I am trying to create an application which displays recent 10 Logs from a file, and have checkboxes to filter the logs based on types,<br />
here is my code:</p>
<p dir="auto"><strong>logdisplay.cpp</strong></p>
<pre><code>#include "logdisplay.h"
#include &lt;QFile&gt;
#include &lt;QHBoxLayout&gt;
#include &lt;QLabel&gt;
#include &lt;QTextStream&gt;
#include &lt;QTimer&gt;
#include &lt;QVBoxLayout&gt;

LogDisplay::LogDisplay(QWidget *parent)
    : QWidget(parent)
{
    QVBoxLayout *mainLayout = new QVBoxLayout(this);

    QHBoxLayout *checkBoxLayout = new QHBoxLayout;
    infoCheckBox = new QCheckBox("INFO");
    infoCheckBox-&gt;setChecked(true);
    checkBoxLayout-&gt;addWidget(infoCheckBox);
    warnCheckBox = new QCheckBox("WARN");
    warnCheckBox-&gt;setChecked(true);
    checkBoxLayout-&gt;addWidget(warnCheckBox);
    debugCheckBox = new QCheckBox("DEBUG");
    debugCheckBox-&gt;setChecked(true);
    checkBoxLayout-&gt;addWidget(debugCheckBox);
    mainLayout-&gt;addLayout(checkBoxLayout);

    readLogs();

    QTimer *timer = new QTimer(this);
    connect(timer, &amp;QTimer::timeout, this, &amp;LogDisplay::refresh);
    timer-&gt;start(5000);
}



void LogDisplay::readLogs()
{
    QFile file("home/arpitk/QT Projects/logtail1/sample.log");
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
        return;

    QTextStream in(&amp;file);
    QStringList logLines;
    while (!in.atEnd()) {
        logLines.append(in.readLine());
    }

    int logLinesCount = logLines.count();
    int startIndex = logLinesCount &gt; 10 ? logLinesCount - 10 : 0;

    for (int i = startIndex; i &lt; logLinesCount; i++) {
        QString message = logLines.at(i);
        QString level = message.left(5);
        if ((level == "INFO " &amp;&amp; infoCheckBox-&gt;isChecked()) ||
            (level == "WARN " &amp;&amp; warnCheckBox-&gt;isChecked()) ||
            (level == "DEBUG" &amp;&amp; debugCheckBox-&gt;isChecked())) {
            mainLayout-&gt;addWidget(new QLabel(message));
        }
    }

    file.close();
}

    void LogDisplay::refresh()
            {
                QLayoutItem *child;
                while ((child = mainLayout-&gt;takeAt(1)) != 0) {
                    delete child-&gt;widget();
                    delete child;
                }
                readLogs();
            }
    LogDisplay::~LogDisplay()
    {
    }

</code></pre>
<p dir="auto"><strong>main.cpp</strong></p>
<pre><code>#include "logdisplay.h"
#include &lt;QApplication&gt;

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    LogDisplay w;
    w.show();
    return a.exec();
}

</code></pre>
<p dir="auto">The code is executing and checkboxes are displaying but Log Window is not showing?<br />
<img src="https://ddgobkiprc33d.cloudfront.net/6cb8dbae-1c94-41f6-a2cc-6db9d51d5965.png" alt="Screenshot 2023-02-09 182317.png" class=" img-fluid img-markdown" /><br />
The log window is not showing, Please help!</p>
]]></description><link>https://forum.qt.io/topic/142812/log-window-not-showing</link><generator>RSS for Node</generator><lastBuildDate>Fri, 10 Apr 2026 16:53:40 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/142812.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 09 Feb 2023 12:53:55 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Log Window Not Showing! on Fri, 10 Feb 2023 05:12:51 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> <a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a> after debugging i got to know that QFile was not reading file, got it solved and not its working perfectly. Thankyou for all you help and kind support.</p>
]]></description><link>https://forum.qt.io/post/747003</link><guid isPermaLink="true">https://forum.qt.io/post/747003</guid><dc:creator><![CDATA[Aviral 0]]></dc:creator><pubDate>Fri, 10 Feb 2023 05:12:51 GMT</pubDate></item><item><title><![CDATA[Reply to Log Window Not Showing! on Thu, 09 Feb 2023 17:35:27 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/aviral-0">@<bdi>Aviral-0</bdi></a><br />
You must either step through in a debugger or put in <code>qDebug()</code> messages.  We (i.e. you!) need to know whether/when lines are being read from the log file and whether/when they are (attempted to be) displayed.</p>
]]></description><link>https://forum.qt.io/post/746960</link><guid isPermaLink="true">https://forum.qt.io/post/746960</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Thu, 09 Feb 2023 17:35:27 GMT</pubDate></item><item><title><![CDATA[Reply to Log Window Not Showing! on Thu, 09 Feb 2023 17:20:36 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> <a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a> I am new to all this, appreciate your patience!<br />
This is my updated code, I have tried to keep all of your suggestions in mind. and this is I come up with.<br />
The application is building but still no logs are shown :'(<br />
And yes the file contains log information for which I am putting absolute path.</p>
<pre><code>#include "logdisplay.h"
#include &lt;QFileSystemWatcher&gt;
#include &lt;QFile&gt;
#include &lt;QTextStream&gt;
#include &lt;QVBoxLayout&gt;
#include &lt;QHBoxLayout&gt;
#include &lt;QCheckBox&gt;
#include &lt;QPlainTextEdit&gt;
#include &lt;QTextCursor&gt;
#include &lt;QToolBar&gt;

LogDisplay::LogDisplay(QWidget *parent)
    : QMainWindow(parent)
{
    // Create the log display widget
    logDisplay = new QPlainTextEdit(this);
    logDisplay-&gt;setReadOnly(true);

    // Create the error checkbox
    errorCheckbox = new QCheckBox("Error", this);
    errorCheckbox-&gt;setChecked(true);

    // Create the warning checkbox
    warningCheckbox = new QCheckBox("Warning", this);
    warningCheckbox-&gt;setChecked(true);

    // Create the info checkbox
    infoCheckbox = new QCheckBox("Info", this);
    infoCheckbox-&gt;setChecked(true);

    // Create a horizontal layout for the checkboxes
    QHBoxLayout *checkboxLayout = new QHBoxLayout;
    checkboxLayout-&gt;addWidget(errorCheckbox);
    checkboxLayout-&gt;addWidget(warningCheckbox);
    checkboxLayout-&gt;addWidget(infoCheckbox);

    // Create a vertical layout for the log display and checkboxes
    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout-&gt;addWidget(logDisplay);
    mainLayout-&gt;addLayout(checkboxLayout);

    // Create a central widget and set its layout
    QWidget *centralWidget = new QWidget(this);
    centralWidget-&gt;setLayout(mainLayout);
    setCentralWidget(centralWidget);

    // Create a toolbar for the checkboxes
    QToolBar *filterToolBar = addToolBar("Filter");
    filterToolBar-&gt;addWidget(errorCheckbox);
    filterToolBar-&gt;addWidget(warningCheckbox);
    filterToolBar-&gt;addWidget(infoCheckbox);

    // Connect the checkbox state changed signals to the updateLogDisplay slot
    connect(errorCheckbox, &amp;QCheckBox::stateChanged, this, &amp;LogDisplay::updateLogDisplay);
    connect(warningCheckbox, &amp;QCheckBox::stateChanged, this, &amp;LogDisplay::updateLogDisplay);
    connect(infoCheckbox, &amp;QCheckBox::stateChanged, this, &amp;LogDisplay::updateLogDisplay);

    // Create a QFileSystemWatcher to monitor the log file
    QFileSystemWatcher *watcher = new QFileSystemWatcher(this);
    connect(watcher, &amp;QFileSystemWatcher::fileChanged, this, &amp;LogDisplay::updateLogList);
    watcher-&gt;addPath("log.txt");

    // Initialize the log display with the first set of logs
    updateLogList();
}

LogDisplay::~LogDisplay()
{
}

bool LogDisplay::updateLogList()
{
    // Open the log file
    QFile logFile("/home/arpitk/QT Projects/logtail1/sample.log");
    if (!logFile.open(QFile::ReadOnly | QFile::Text))
        return false;

    // Read the logs from the log file into the log line
    logList.clear();
    QTextStream in(&amp;logFile);
    while (!in.atEnd()) {
    logList.prepend(in.readLine());
    }
    // Close the log file
    logFile.close();

    // Update the log display with the new logs
    updateLogDisplay();

    return true;
    }
void LogDisplay::updateLogDisplay()
{
// Clear the current log display
logDisplay-&gt;clear();
// Iterate over the logs in the log list
QTextCursor cursor(logDisplay-&gt;document());
for (int i = 0; i &lt; logList.size(); ++i) {
    // Check if the log should be displayed based on the filter
    QString log = logList[i];
    if ((log.contains("Error") &amp;&amp; errorCheckbox-&gt;isChecked()) ||
        (log.contains("Warning") &amp;&amp; warningCheckbox-&gt;isChecked()) ||
        (log.contains("Info") &amp;&amp; infoCheckbox-&gt;isChecked())) {
        // Insert the log into the log display
        cursor.insertText(log + "\n");
    }
}
}

</code></pre>
]]></description><link>https://forum.qt.io/post/746957</link><guid isPermaLink="true">https://forum.qt.io/post/746957</guid><dc:creator><![CDATA[Aviral 0]]></dc:creator><pubDate>Thu, 09 Feb 2023 17:20:36 GMT</pubDate></item><item><title><![CDATA[Reply to Log Window Not Showing! on Thu, 09 Feb 2023 13:58:19 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/aviral-0">@<bdi>Aviral-0</bdi></a><br />
I would start by changing the way you do stuff.  All this creating individual <code>QLabel</code>s for each message and deleting widgets/layout items is not a good way, for many reasons.  For displaying log lines just append to a <code>Q[Plain]TextEdit</code>, or possibly use a <code>QListView</code> or <code>QListWidget</code>.  You might also benefit from separating responsibilities, so <code>readLogs()</code> might just read the lines with no UI stuff and something else be responsible for displaying them.</p>
]]></description><link>https://forum.qt.io/post/746929</link><guid isPermaLink="true">https://forum.qt.io/post/746929</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Thu, 09 Feb 2023 13:58:19 GMT</pubDate></item><item><title><![CDATA[Reply to Log Window Not Showing! on Thu, 09 Feb 2023 13:33:43 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/aviral-0">@<bdi>Aviral-0</bdi></a> Did you do any debugging?<br />
You call readLogs() only once in the constructor.<br />
Does "home/arpitk/QT Projects/logtail1/sample.log" contain anything?<br />
You should really first do at least some debugging...</p>
]]></description><link>https://forum.qt.io/post/746928</link><guid isPermaLink="true">https://forum.qt.io/post/746928</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Thu, 09 Feb 2023 13:33:43 GMT</pubDate></item></channel></rss>