I have a pop-up widget that shows on entering a specific cell of QTableWidget. And I'm closing the pop-up window on leave event.
The pop-up widget has got some QLabels, which are set as URLs. When I click on a hyperlink(QLabel), the link is opened in my browser. And when I click on another url Qlabel, the link is opened, but my application crashes immediately.
One observation is if the mouse is taken out of the pop-up window, before it takes time to open the link in the browser, the application doesn't crash.
//cpopupwindow.h
// this closes the window when the mouse is out of widget
protected:
{
if(event
->type
() == QEvent::Leave) {
if(isVisible())
{
while(!cveReferences.isEmpty())
{
delete cveReferences.takeFirst();
}
this->close();
}
}
return QWidget::eventFilter(object, event
);
}
//cpopupwindow.h
// this closes the window when the mouse is out of widget
protected:
bool eventFilter(QObject * object, QEvent * event)
{
if(event->type() == QEvent::Leave)
{
if(isVisible())
{
while(!cveReferences.isEmpty())
{
delete cveReferences.takeFirst();
}
this->close();
}
}
return QWidget::eventFilter(object, event);
}
To copy to clipboard, switch view to plain text mode
// in cpopupwindow.cpp
this->installEventFilter(this); //in ctor
// this is a public function which displays the content and is called in tablewidget class on cellEnter()
void CPopupWindow::someFunction()
{
// This is how I add the text to QLabels
if("CVE" == repoType)
{
cceReference_table->setVisible(false);
for(int i = 0; i < lst.count(); i++)
{
cveReferences.
append(new QLabel());
cveReferences.at(i)->setText("<a href=\"" + references.value(lst.at(i)) + "\">" +
lst.at(i) + "</a>");
cveReferences.at(i)->setTextFormat(Qt::RichText);
cveReferences.at(i)->setTextInteractionFlags(Qt::TextBrowserInteraction);
cveReferences.at(i)->setOpenExternalLinks(true);
vLyt->addWidget(cveReferences.at(i));
}
}
}
// in cpopupwindow.cpp
this->installEventFilter(this); //in ctor
// this is a public function which displays the content and is called in tablewidget class on cellEnter()
void CPopupWindow::someFunction()
{
// This is how I add the text to QLabels
if("CVE" == repoType)
{
cceReference_table->setVisible(false);
for(int i = 0; i < lst.count(); i++)
{
cveReferences.append(new QLabel());
cveReferences.at(i)->setText("<a href=\"" + references.value(lst.at(i)) + "\">" +
lst.at(i) + "</a>");
cveReferences.at(i)->setTextFormat(Qt::RichText);
cveReferences.at(i)->setTextInteractionFlags(Qt::TextBrowserInteraction);
cveReferences.at(i)->setOpenExternalLinks(true);
vLyt->addWidget(cveReferences.at(i));
}
}
}
To copy to clipboard, switch view to plain text mode
Everything is fine until second click of the URL. On second click, if the mouse is not taken out of pop-up widget, then the whole application crashes.
Kindly help me with this. Thank you.
Bookmarks