esafwan
esafwan

Reputation: 18029

Qurl not defined in pyqt

Am learning to program python with qt using eric ide. But there seems to be one error i get.

Its says Global Qurl not defined or something. How can I define Qurl?

from PyQt4.QtGui import QMainWindow

from PyQt4.QtCore import pyqtSignature
from Ui_mainwindow import Ui_MainWindow

class MainWindow(QMainWindow, Ui_MainWindow):
    """
    Class documentation goes here.
    """
    def __init__(self, parent = None):
        """
        Constructor
        """
        QMainWindow.__init__(self, parent)
        self.setupUi(self)

    @pyqtSignature("")
    def on_btnNavigate_released(self):
        """
        Public slot invoked when the user clicks the Navigate Button .
        """
        self.webView.load(QUrl("http://qt.nokia.com/"));

Am following this tutorial

Upvotes: 2

Views: 5851

Answers (2)

ekhumoro
ekhumoro

Reputation: 120628

The code you posted is mostly auto-generated by the Eric4 IDE as part of the tutorial you posted a link to.

If you read this page of the tutorial carefully, it mentions importing QUrl in the paragraph following a code snippet for the on_btnNavigate_released method (near the bottom of the page):

Notice that for this to work, we have to import QUrl (take a look at the source code accompanying the tutorial).

Although, to be fair to you, the source code snippet doesn't actually show the relevant import line! It should probably look something more like this:

from PyQt4.QtCore import pyqtSignature, QUrl
...

@pyqtSignature("")
def on_btnNavigate_released(self):
    """
    Slot documentation goes here.
    """
    self.webView.setUrl(QUrl(self.txtUrl.text()))

Upvotes: 4

Eli Bendersky
Eli Bendersky

Reputation: 273536

You didn't import QUrl from anywhere. Do this:

from PyQt4.QtCore import *

Note that you could also just import QUrl from QtCore, but a * import here is commonplace, since QtCore is huge and all classes have the Q prefix so it's not hard to guess where they came from. This is a matter of style of course, but personally I do use * imports from QtCore and QtGui. The PyQt book samples do the same.

Upvotes: 0

Related Questions