Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[solved]url recognition in qt
Hello, I'm working with the QUrl class. My problem is that I have to trigger an action if the recognize a specific url.
if(url = "http://myurl.com)
But It doesn't work.
guziemic last edited by
You cannot compare whole QUrl class to string, but you can use following comparison.
If you would like to have just whole URL you could use "QUrl:toString":http://doc.qt.digia.com/stable/qurl.html#toString
If you are interested only in domain you could use "QUrl:host":http://doc.qt.digia.com/stable/qurl.html#host
Hope it help.
adnan last edited by
Your code is syntactically incorrect:
@ void MyClass::trigger(QUrl*url)
if(url == "http://myurl.com")
Besides, if you are trying to load any gui component, it is only possibly through mainwindow class. Non-gui classes can't display any gui components. You need to send a signal to main gui class to display any gui component.
Thanks QUrl::toString works great!
elmigranto last edited by
Comparing pointer with a string is just sick, bro (sintatically correct and can even return true though).
That was only an example to explain my problem, I know that a QUrl can't be a boolean.