1

Here's the code:

import sys,os
import win32api
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
import ctypes
from PyQt4 import uic


class HelloWorld:

    def __init__(self, iface):  

        self.iface = iface
        self.canvas = iface.mapCanvas()
        self.connect(self.ui.pushButton,QtCore.SIGNAL("clicked()"),self.function)

    def initGui(self):       
        self.action = QAction(QIcon(":/plugins/"), "&HelloWorld", self.iface.mainWindow())
        self.action.setWhatsThis("Configuration for test plugin")
        self.action.setStatusTip("This is status tip")
        QObject.connect(self.action, SIGNAL("activated()"), self.hello_world)


        self.iface.addPluginToMenu("HelloWorld", self.action)   


    def unload(self):    
        self.iface.removePluginMenu("HelloWorld",self.action)
        self.iface.removeToolBarIcon(self.action)


    def function( self ):
        QMessageBox.information(self.iface.mainWindow(), QCoreApplication.translate('HelloWorld', "HelloWorld"), QCoreApplication.translate('HelloWorld', "HelloWorld"))

    def hello_world(self):

        path = os.path.dirname( os.path.abspath( __file__ ) )
        self.optionsDialog = uic.loadUi(os.path.join(path,"untitled.ui"))


if __name__ == "__main__":
pass

And here is the error:

Traceback (most recent call last):
  File "C:/PROGRA~1/Quantum GIS Lisboa/apps/qgis/./python\qgis\utils.py", line 164, in startPlugin
    plugins[packageName] = package.classFactory(iface)
  File "C:/Users/User/.qgis//python/plugins\HelloWorld\__init__.py", line 15, in classFactory
    return HelloWorld(iface)
  File "C:/Users/User/.qgis//python/plugins\HelloWorld\HelloWorld.py", line 21, in __init__
    self.connect(self.ui.pushButton,QtCore.SIGNAL("clicked()"),self.function)
AttributeError: HelloWorld instance has no attribute 'connect'

How can I resolve my problem?

1

HelloWorld is not a subclass of any Qt class that supports the connect method. I suggest you use the "Plugin Builder" plugin to generate a template for you. This will get you started in the right direction.

  • I'm just trying to add a function to the action button.so that when you click to button a specific action occurred. Maybe there's another way? – Cathrin May 5 '13 at 18:28
  • if I write here so that the error does not occur. but in this row specify the action on the button? QObject.connect(self.action, SIGNAL("clicked()"),self.function) – Cathrin May 6 '13 at 6:36
  • Use: self.action.triggered.connect(self.function) – gsherman May 6 '13 at 14:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.