I want to add a hyperlink to a textBrowser in order to open a dialog.
To be specific, I am using the textBrowser as a error messages window and if I click to a message I want to open a dialog. I made a hyperlink that opens website with ui.textBrowser.append("<a href=https://www.google.com>Google</a>")
but as I said, I want the link to run a function in order to display a dialog.
I tried something like this:
void dlgMessages::on_btnerr_clicked()
{
QString linkText = "<a href=\"helloLink\">HELLO</a>";
ui.textBrowser->setOpenExternalLinks(false);
ui.textBrowser->moveCursor(QTextCursor::Start);
ui.textBrowser->append(linkText);
}
void dlgMessages::handleLinkClicked(const QUrl& url)
{
if (url.toString() == "helloLink") {
qDebug() << "Hello Guys";
}
}
Those functions simply does append a hyperlink to the textBrowser and when user click the message and if the message's link is "helloLink", I expect an output that says "Hello Guys". But I got QTextBrowser: No document for helloLink
.