![]() |
2010-02-17
, 20:13
|
Posts: 3,319 |
Thanked: 5,610 times |
Joined on Aug 2008
@ Finland
|
#22
|
[*]Can someone explain simply how i get a button to call a function please? - i understand the "def part" - created a function, but really can't figure out how to simply call it from the button... is there any easy guide?
The Following User Says Thank You to attila77 For This Useful Post: | ||
![]() |
2010-02-17
, 20:15
|
|
Posts: 3,203 |
Thanked: 1,391 times |
Joined on Nov 2009
@ Worthing, England
|
#23
|
self.connect(self.myButton, QtCore.SIGNAL("clicked()"), self.clickFoo)
(obviously the exact object names will differ, but you get the idea)
![]() |
2010-02-17
, 20:20
|
Posts: 3,428 |
Thanked: 2,856 times |
Joined on Jul 2008
|
#24
|
meh ok maybe i needed more, as that doesnt explain where the function name is that i am calling..... which is where i am getting confused....
That starts a signal...?!(i think?)
I then need to figure out how to catch that and run a function?! lol
or is that the self.clickFoo part? (if the function is not part of the same class is it just clickFoo? )
(Or is it just me being confuzzled?)
The Following 2 Users Say Thank You to fatalsaint For This Useful Post: | ||
![]() |
2010-02-17
, 20:23
|
|
Posts: 3,203 |
Thanked: 1,391 times |
Joined on Nov 2009
@ Worthing, England
|
#25
|
Yes to the last.. I guess my tutorial wasn't clear enough.. this is exactly what it is demonstrating.
That last part in his signal: self.clickFoo() < the function name is clickFoo().
If you use "self." that means within the same class as you are connecting the signal too. So you'll create def clickFoo: within the QT class for the main window.
If you want to call functions from other places.. you would pass the appropriate object to the function call in the self.clickFoo() part. If it's a global function, just "clickFoo()", etc.
The Following User Says Thank You to noobmonkey For This Useful Post: | ||
![]() |
2010-02-17
, 21:58
|
|
Posts: 3,203 |
Thanked: 1,391 times |
Joined on Nov 2009
@ Worthing, England
|
#26
|
![]() |
2010-02-17
, 21:59
|
Posts: 3,428 |
Thanked: 2,856 times |
Joined on Jul 2008
|
#27
|
ok well tried it....
my class is
class Ui_MainWindow(object):
The error is:
Attribute error: 'UI_MainWindow' object has no attribute 'connect'
Button call in class, sub function, def setupUi(self, MainWindow):
self.connect(self.pushButton, QtCore.SIGNAL("clicked()"), self.updateTab1)
Function in Class:
def updateTab1(self, MainWindow):
QtCore.QObject.connect(self.ui.btnAdd, QtCore.SIGNAL('clicked()'), self.doAdd)
self.ui = Ui_MainWindow()
![]() |
2010-02-17
, 22:05
|
|
Posts: 3,203 |
Thanked: 1,391 times |
Joined on Nov 2009
@ Worthing, England
|
#28
|
If you do it that way You might need self.ui.btnName.connect....
Do it like I do it in my tutorial
ETA: Also self.pushButton I don't think is going to work.. do you have a line similar to:Code:QtCore.QObject.connect(self.ui.btnAdd, QtCore.SIGNAL('clicked()'), self.doAdd)
Then you need to use self.ui.pushButton...Code:self.ui = Ui_MainWindow()
Wait - looking at your code - are you using pyuic4 or did you write your own qt interface in the code?
![]() |
2010-02-17
, 22:06
|
|
Posts: 3,203 |
Thanked: 1,391 times |
Joined on Nov 2009
@ Worthing, England
|
#29
|
If you do it that way You might need self.ui.btnName.connect....
Wait - looking at your code - are you using pyuic4 or did you write your own qt interface in the code?
![]() |
2010-02-17
, 22:08
|
Posts: 3,428 |
Thanked: 2,856 times |
Joined on Jul 2008
|
#30
|
![]() |
Tags |
code, health check, n900, python |
Thread Tools | |
|
i got a function working 15 mins ago! - and i'm now commenting my work, so once that is done, i'm goi ng to try and split it into more functions
----------- Follow me on Twitter here
----------- My Photography Website and Blog is here
----------- Author of the N900 Health Check Application ----------- New Version in Extras Devel (Dec 2010 - 2.9.10)
----------- Are you on the N900 World Map? - http://pininthemap.com/maemo - masterpin: shotgun
----------- What apps do you want to see on the n900 or in MeeGo in the future? -