<?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[[SOLVED] ListView not closed when the Application is closed]]></title><description><![CDATA[<p dir="auto">I have to set the Auto Completion for the QLineEdit. Here am using a QListView to display the suggestion list. Also am using QSortFilterProxyModel for sorting and filtering the items. Sorting and filtering works fine. <em>The problem is when i close the application the ListView is not getting closed until i force close the list view</em>. Herewith i have included my code and the snapshot of my output. How can i close the List View when the application is closed.  Please suggest your views about it.</p>
<p dir="auto"><em>LEAutoCompletion.h</em></p>
<p dir="auto">@#ifndef LEAUTOCOMPLETION_H<br />
#define LEAUTOCOMPLETION_H</p>
<p dir="auto">#include &lt;QWidget&gt;<br />
#include &lt;QLineEdit&gt;<br />
#include &lt;QListView&gt;<br />
#include &lt;QModelIndex&gt;</p>
<p dir="auto">namespace Ui {<br />
class LEAutoCompletion;<br />
}</p>
<p dir="auto">class LEAutoCompletion : public QWidget<br />
{<br />
Q_OBJECT</p>
<p dir="auto">public:<br />
explicit LEAutoCompletion(QWidget *parent = 0);<br />
~LEAutoCompletion();</p>
<p dir="auto">private:<br />
Ui::LEAutoCompletion *ui;<br />
QLineEdit *mLineEdit;<br />
QListView *mView;</p>
<p dir="auto">protected:<br />
bool eventFilter(QObject *target, QEvent *event);</p>
<p dir="auto">private slots:<br />
void onTextChanged(const QString &amp;text);<br />
void completeText(const QModelIndex &amp;);<br />
void textModified();<br />
};</p>
<p dir="auto">#endif // LEAUTOCOMPLETION_H@</p>
<p dir="auto"><em>LEAutoCompletion.cpp</em></p>
<p dir="auto">@#include "LEAutoCompletion.h"<br />
#include "ui_LEAutoCompletion.h"<br />
#include &lt;QVBoxLayout&gt;<br />
#include &lt;QStringListModel&gt;<br />
#include &lt;QSortFilterProxyModel&gt;<br />
#include &lt;QEvent&gt;<br />
#include &lt;QKeyEvent&gt;</p>
<p dir="auto">LEAutoCompletion::LEAutoCompletion(QWidget *parent) :<br />
QWidget(parent),<br />
ui(new Ui::LEAutoCompletion)<br />
{<br />
ui-&gt;setupUi(this);<br />
mLineEdit = new QLineEdit(this);</p>
<pre><code>QVBoxLayout *layout = new QVBoxLayout(this);
layout-&gt;addWidget(mLineEdit);
setLayout(layout);

knownList = NULL;

setWindowTitle("Auto Completion");

QStringList  list;
list&lt;&lt; "America"&lt;&lt;"Arica"&lt;&lt;"Belgium"&lt;&lt;"Canada"&lt;&lt;"Denmark"&lt;&lt;"India"&lt;&lt;"France"&lt;&lt;"Australia";

QStringListModel *model = new QStringListModel(this);
model-&gt;setStringList(list);

QSortFilterProxyModel *filterModel = new QSortFilterProxyModel(this);
filterModel-&gt;setSourceModel(model);
filterModel-&gt;setFilterCaseSensitivity(Qt::CaseInsensitive);
filterModel-&gt;sort(0,Qt::AscendingOrder);

mView = new QListView(this);
mView-&gt;setModel(filterModel);
mView-&gt;setEditTriggers(QAbstractItemView::NoEditTriggers);
mView-&gt;setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
mView-&gt;setSelectionBehavior(QAbstractItemView::SelectRows);
mView-&gt;setSelectionMode(QAbstractItemView::SingleSelection);
mView-&gt;setParent(0, Qt::ToolTip);
mView-&gt;setFocusPolicy(Qt::NoFocus);
mView-&gt;setFocusProxy(mLineEdit);

connect(mLineEdit, SIGNAL(textChanged(QString)) , filterModel , SLOT(setFilterWildcard(QString)));
connect(mLineEdit, SIGNAL(editingFinished()), this, SLOT(textModified()));
connect(mLineEdit, SIGNAL(textChanged(QString)), this, SLOT(onTextChanged(const QString &amp;)));
connect(mView, SIGNAL(activated(const QModelIndex &amp;)), this, SLOT(completeText(const QModelIndex &amp;)));
connect(mView, SIGNAL(clicked(const QModelIndex &amp;)), this, SLOT(completeText(const QModelIndex &amp;)));
installEventFilter(this);
</code></pre>
<p dir="auto">}</p>
<p dir="auto">LEAutoCompletion::~LEAutoCompletion()<br />
{<br />
delete ui;<br />
delete mView;<br />
}</p>
<p dir="auto">bool LEAutoCompletion::eventFilter(QObject *target, QEvent *event)<br />
{<br />
if(target == this)<br />
{<br />
if(event-&gt;type() == QEvent::Resize || event-&gt;type() == QEvent::Move)<br />
{<br />
int lineEditWidth = mLineEdit-&gt;width();<br />
mView-&gt;setMinimumWidth(lineEditWidth);<br />
mView-&gt;setMaximumWidth(lineEditWidth);<br />
mView-&gt;setMaximumHeight(100);</p>
<pre><code>        QPoint p(0, mLineEdit-&gt;height());
        int x = mLineEdit-&gt;mapToGlobal(p).x();
        int y = mLineEdit-&gt;mapToGlobal(p).y();
        mView-&gt;move(x, y);
    }
}
return QWidget::eventFilter(target, event);
</code></pre>
<p dir="auto">}</p>
<p dir="auto">void LEAutoCompletion::onTextChanged(const QString &amp;text)<br />
{<br />
if(text.isEmpty())<br />
{<br />
mView-&gt;hide();<br />
}<br />
else<br />
{<br />
mView-&gt;show();<br />
}<br />
}</p>
<p dir="auto">void LEAutoCompletion::completeText(const QModelIndex &amp;index)<br />
{<br />
mLineEdit-&gt;setText(index.data().toString());<br />
}</p>
<p dir="auto">void LEAutoCompletion::textModified()<br />
{<br />
QString text = mLineEdit-&gt;text();<br />
}<br />
@</p>
<p dir="auto"><em>OUTPUT:</em></p>
<p dir="auto">![IMG]<a href="http://i.imgur.com/Y4uKrOJ.png%5B/IMG%5D" target="_blank" rel="noopener noreferrer nofollow ugc">http://i.imgur.com/Y4uKrOJ.png[/IMG]</a>(ListView Suggestion List)!</p>
<p dir="auto"><em>Image of List View not Closed after the Application is closed.</em></p>
<p dir="auto">![IMG]<a href="http://i.imgur.com/JLEQRnO.png%5B/IMG%5D" target="_blank" rel="noopener noreferrer nofollow ugc">http://i.imgur.com/JLEQRnO.png[/IMG]</a>(ListView not closed after application closed)!</p>
]]></description><link>https://forum.qt.io/topic/26249/solved-listview-not-closed-when-the-application-is-closed</link><generator>RSS for Node</generator><lastBuildDate>Tue, 18 Aug 2026 11:42:30 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/26249.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 16 Apr 2013 12:46:42 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [SOLVED] ListView not closed when the Application is closed on Tue, 16 Apr 2013 13:08:47 GMT]]></title><description><![CDATA[<p dir="auto">Thanks a lot <em>raven-worx</em>. That works fine.... :-)</p>
]]></description><link>https://forum.qt.io/post/173908</link><guid isPermaLink="true">https://forum.qt.io/post/173908</guid><dc:creator><![CDATA[Macro]]></dc:creator><pubDate>Tue, 16 Apr 2013 13:08:47 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] ListView not closed when the Application is closed on Tue, 16 Apr 2013 12:58:21 GMT]]></title><description><![CDATA[<p dir="auto">your problem is the following line:<br />
@mView-&gt;setParent(0, Qt::ToolTip);@</p>
<p dir="auto">Since you set the parent to 0 it wont get deleted when it's parent gets deleted. I assume you jsut want to set the window flag to Qt::ToolTip?<br />
You should use the "QWidget::setWindowFlags()":<a href="http://qt-project.org/doc/qt-4.8/qwidget.html#windowFlags-prop" target="_blank" rel="noopener noreferrer nofollow ugc">http://qt-project.org/doc/qt-4.8/qwidget.html#windowFlags-prop</a></p>
]]></description><link>https://forum.qt.io/post/173909</link><guid isPermaLink="true">https://forum.qt.io/post/173909</guid><dc:creator><![CDATA[raven-worx]]></dc:creator><pubDate>Tue, 16 Apr 2013 12:58:21 GMT</pubDate></item></channel></rss>