Menu

Main Menu
Talk Get Daily Search

Member's Online

    User Name
    Password

    Request-Help pyqt attribute error.

    Reply
    Dimand | # 1 | 2010-09-02, 06:45 | Report

    I have been messing around with pyqt but i have hit a brick wall with this.

    Basically, i used the designer to create a gui and the main code is the program, but i keep getting an attribute error when i try and make a function for some buton.

    Code:
    #!/usr/bin/python2.5
    import sys
    from PyQt4 import QtGui,QtCore
    from sms_ui import *
    
    class Awesome(QtGui.QMainWindow):
            def __init__(self, parent=None):
                    #build parent user interface
                    QtGui.QWidget.__init__(self, parent)
                    self.ui = Ui_MainWindow()
                    self.ui.setupUi(self)
                    QtCore.QObject.connect(self.ui.btnSend, QtCore.SIGNAL('clicked()'), self.smsgo)
    
    		def smsgo(self):
    				a=1
    
    if __name__ == "__main__":
            #This function means this was run directly, not called from another python file.
            app = QtGui.QApplication(sys.argv)
            myapp = Awesome()
            myapp.show()
            sys.exit(app.exec_())
    I cant see what is wrong here. if i remove

    Code:
    QtCore.QObject.connect(self.ui.btnSend, QtCore.SIGNAL('clicked()'), self.smsgo)
    
    		def smsgo(self):
    				a=1
    The GUI is fine. I have double checked the names of everything.

    Any insight?

    Edit | Forward | Quote | Quick Reply | Thanks

     
    nicolai | # 2 | 2010-09-02, 07:05 | Report

    Can you post the error message?
    And it looks like the function definition has
    wrong indentation.

    nicolai

    Edit | Forward | Quote | Quick Reply | Thanks

     
    Dimand | # 3 | 2010-09-02, 07:11 | Report

    Yes. That was it. :\

    I am going to have to be careful about that.

    Sorry to waste your time, though i'm sure i will have more problems soon enough.

    Edit | Forward | Quote | Quick Reply | Thanks

     
    Dimand | # 4 | 2010-09-02, 11:11 | Report

    Ok, I have a new question.

    Here is my code snipit

    Code:
    manager = QNetworkAccessManager(self);
    		connect(manager, SIGNAL(finished("QNetworkReply*")), self, SLOT(replyFinished("QNetworkReply*")));
    		manager.post(QNetworkRequest(QUrl(sms)));
    I get this error:
    nameerror: global name 'Qnetworkaccessmanager' is not defined

    The Qnetworkaccessmanager is defiantly confusing me a bit. Any hints in the right direction?

    Edit | Forward | Quote | Quick Reply | Thanks

     
    peppe78 | # 5 | 2010-09-02, 11:39 | Report

    Originally Posted by Dimand View Post
    Ok, I have a new question.

    Here is my code snipit

    Code:
    manager = QNetworkAccessManager(self);
    		connect(manager, SIGNAL(finished("QNetworkReply*")), self, SLOT(replyFinished("QNetworkReply*")));
    		manager.post(QNetworkRequest(QUrl(sms)));
    I get this error:
    nameerror: global name 'Qnetworkaccessmanager' is not defined

    The Qnetworkaccessmanager is defiantly confusing me a bit. Any hints in the right direction?
    check the Capitalizing?

    'Qnetworkaccessmanager' => 'QNetworkAccessManager'

    it's right here in the code but probably not in your
    script, because in the nameerror only the first letter is a capital??

    Edit | Forward | Quote | Quick Reply | Thanks

     
    Dimand | # 6 | 2010-09-02, 11:49 | Report

    I typed the name error out and forgot the caps.
    It is still caps in my code.

    Should i use http instead?

    Edit | Forward | Quote | Quick Reply | Thanks

     
    nicolai | # 7 | 2010-09-02, 11:54 | Report

    Missing import statement?
    Something like
    from PyQt4.QtNetwork import QNetworkAccessManager

    nicolai

    Edit | Forward | Quote | Quick Reply | Thanks

     
    Dimand | # 8 | 2010-09-02, 11:59 | Report

    Originally Posted by nicolai View Post
    Missing import statement?
    Something like
    from PyQt4.QtNetwork import QNetworkAccessManager

    nicolai
    I had
    from PyQt4 import QtGui,QtCore,QtNetwork
    seems i needed
    from PyQt4.QtNetwork import QNetworkAccessManager
    too.

    now it is telling me connect is not defined, but i can probably work that out.

    Edit | Forward | Quote | Quick Reply | Thanks

     
    Dimand | # 9 | 2010-09-03, 01:06 | Report

    Ok, So i have a program that works.
    It sends an sms through exetel

    Code:
    #!/usr/bin/python2.5
    import sys
    from PyQt4 import QtGui,QtCore,QtNetwork
    from PyQt4.QtNetwork import QNetworkAccessManager
    from sms2_ui import *
    
    class MyForm(QtGui.QMainWindow):
    	def __init__(self, parent=None):
    		#build parent user interface
    		QtGui.QWidget.__init__(self, parent)
    		self.ui = Ui_MainWindow()
    		self.ui.setupUi(self)
    		QtCore.QCoreApplication.setOrganizationName("Dimand Corp")
    		QtCore.QCoreApplication.setApplicationName("SMS Exetel")
    		self.settings = QtCore.QSettings()
    
    		#connect buttons
    		QtCore.QObject.connect(self.ui.btnSMS, QtCore.SIGNAL('clicked()'), self.doAddNew)
    		QtCore.QObject.connect(self.ui.actionFrom_2, QtCore.SIGNAL('triggered()'), self.doSetNum)
    		QtCore.QObject.connect(self.ui.actionUsername_3, QtCore.SIGNAL('triggered()'), self.doSetName)
    		QtCore.QObject.connect(self.ui.actionPassword_3, QtCore.SIGNAL('triggered()'), self.doSetPass)
    		QtCore.QObject.connect(self.ui.actionQuit, QtCore.SIGNAL('triggered()'), QtGui.qApp, QtCore.SLOT('quit()'))
    
    		#Create Sub's
    	def doAddNew(self):
    		msg = self.ui.plainTextEditSMS.toPlainText()
    		user = self.settings.value("Username").toString()
    		password = self.settings.value("Password").toString()
    		fromnum = self.settings.value("FromNum").toString()
    		sms = "https://smsgw.exetel.com.au/sendsms/api_sms.php?username="+ user + "&password=" + password + "&mobilenumber=" + self.ui.lineTo.displayText() + "&message=" + msg + "&sender=" + fromnum + "&messagetype=Text"
    		self.manager = QNetworkAccessManager(self);
    		#QtCore.QObject.connect(self.manager, QtCore.SIGNAL('finished("QNetworkReply*")'),self, QtCore.SLOT('finished("QNetworkReply*")'));
    		self.manager.get(QtNetwork.QNetworkRequest(QtCore.QUrl(sms)));
    		self.ui.lineTo.clear()
    		self.ui.plainTextEditSMS.clear()
    
    	def doSetNum(self):
    		text, ok = QtGui.QInputDialog.getText(self, "Settings",
    		"Send Number:", QtGui.QLineEdit.Normal,
    		QtCore.QDir.home().dirName())
    		if ok and text != '':
    			self.settings.setValue("FromNum", text)
    
    	def doSetName(self):
    		text, ok = QtGui.QInputDialog.getText(self, "Settings",
    		"Username:", QtGui.QLineEdit.Normal,
    		QtCore.QDir.home().dirName())
    		if ok and text != '':
    			self.settings.setValue("Username", text)
    
    	def doSetPass(self):
    		text, ok = QtGui.QInputDialog.getText(self, "Settings",
    		"Password:", QtGui.QLineEdit.Normal,
    		QtCore.QDir.home().dirName())
    		if ok and text != '':
    			self.settings.setValue("Password", text)
    
    if __name__ == "__main__":
    		#This function means this was run directly, not called from another python file.
    		app = QtGui.QApplication(sys.argv)
    		myapp = MyForm()
    		myapp.show()
    		sys.exit(app.exec_())
    I would prefer not to have to run it from the terminal ever time though. how can i make it as a executable on my phone?

    Also, I still cant figer out how to get a response back from the network access manager. (hence why the connect is commented out) Any ideas there?

    Edit | Forward | Quote | Quick Reply | Thanks

     
    attila77 | # 10 | 2010-09-11, 10:45 | Report

    See http://wiki.maemo.org/Desktop_file_format

    For the connect, off the top of my head:
    self.connect(self.manager, QtCore.SIGNAL('finished("QNetworkReply*")'),self, lambda x: do_something_with_reply(x)));

    (you don't need the lambda or the parameter if do_something_with_reply is a slot in a QObject or one of it's subclasses)

    Edit | Forward | Quote | Quick Reply | Thanks

     
vBulletin® Version 3.8.8
Normal Logout