[PyQt] Creating a QUrl out of a string

Florian Bruhin me at the-compiler.org
Fri May 5 06:23:00 BST 2017


On Wed, May 03, 2017 at 04:18:27PM -0400, Christopher Probst wrote:
> Hi,
> 
> Sorry for the newbie question. I am trying to create a QUrl out of a
> string. The sample code is here:
> 
> string = QInputDialog.getText(self, "Download URL", "Enter URL to download")
> url = QUrl( str(string) )
> print ("the url is ", url)
> 
> the output gives me
> the url is  PyQt5.QtCore.QUrl('')
> 
> What am I doing wrong?

Hard to say without knowing what you're entering, but you're probably
entering an invalid URL (like example.com instead of
http://example.com).

You might want QUrl.fromUserInput instead:
http://doc.qt.io/qt-5/qurl.html#fromUserInput

Florian

-- 
https://www.qutebrowser.org  | me at the-compiler.org (Mail/XMPP)
   GPG: 916E B0C8 FD55 A072  | https://the-compiler.org/pubkey.asc
         I love long mails!  | https://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20170505/25374dbc/attachment.sig>


More information about the PyQt mailing list