c++ - Make a Label/Text automatically recognizing links in QtQuick/QML? -
i want automatically make links (e.g. https://xmpp.org/) text of text element clickable, link can opened in browser (without manually copying link).
i can't add e.g. <a href="https://xmpp.org/"></a> manually in code, because input comes directly users.
has qt simple solution in qtquick/qml?
you can use that(regex answer);
text { property string text2: "http://www.google.com" text: isvalidurl(text2) ? ("<a href='"+text2+"'>"+text2+"</a>") : text2 onlinkactivated:{ if (isvalidurl(text2)){ qt.openurlexternally("http://www.google.com") } } function isvalidurl(str) { var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\s+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/ return regexp.test(str); } }
Comments
Post a Comment