August 18, 2011

ictsecurity0 ictsecurity0
Lab Rat
4 posts

signal connect with different class

 

hai,

sorry i have a problem to paste the code here. my code http://pastebin.com/kL3Q6B3W

my question is:

  1. self.connect(self.lineedit, QtCore.SIGNAL("returnPressed()"), MyDisplay.updateUi())

can i send the signal (emitted by self.lineedit) to another class which is defined by MyDisplay.updateUi???

or anyone have the example code please tell me

thanks

7 replies

August 18, 2011

Andre Andre
Area 51 Engineer
6031 posts

Disclaimer: I am not familiar with PyQt (or much with Python at all, in fact).

There is no problem at all connecting signals and slots between different classes, as long as those classes are both QObject derived. So in fact, you are connecting two QObjects always.

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

August 18, 2011

Volker Volker
Robot Herder
5428 posts
ictsecurity0 wrote:
hai,
  1. self.connect(self.lineedit, QtCore.SIGNAL("returnPressed()"), MyDisplay.updateUi())

The syntax should be the same on PyQt as on C++:

  1. self.connect(self.lineedit, QtCore.SIGNAL("returnPressed()"), MyDisplay, QtCore.SLOT("updateUi()"))

August 19, 2011

ictsecurity0 ictsecurity0
Lab Rat
4 posts
Volker wrote:
ictsecurity0 wrote:
hai,
  1. self.connect(self.lineedit, QtCore.SIGNAL("returnPressed()"), MyDisplay.updateUi())

The syntax should be the same on PyQt as on C++:

  1. self.connect(self.lineedit, QtCore.SIGNAL("returnPressed()"), MyDisplay, QtCore.SLOT("updateUi()"))

still got the error. I tried alot of method to pass the signal of ‘returnPassed()’ to another class.

the error“IdentationError:expected an indented block..

My code is here http://pastebin.com/wBhWGxCX

i just want to do some simple print feature but failed

thanks

August 19, 2011

Andre Andre
Area 51 Engineer
6031 posts

The code in your pastebin has mismatched parenthesis, I think.

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

August 19, 2011

Volker Volker
Robot Herder
5428 posts

ictsecurity0 wrote:

still got the error. I tried alot of method to pass the signal of ‘returnPassed()’ to another class.

the error“IdentationError:expected an indented block..

I’m by no means a Python export, but that error message looks quite unrelated to Qt… Did you mix up spaces and tabs?

August 20, 2011

ictsecurity0 ictsecurity0
Lab Rat
4 posts

i solved the problem with using lambda:

self.connect(lineedit, QtCore.SIGNAL’), lambda: MyDisplay().updateUi())

anyway, thanks :)

August 20, 2011

Andre Andre
Area 51 Engineer
6031 posts

I think you could have solved it with just an additional closing parentheses ) after the connect statement in your original code…

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

 
  ‹‹ Enable auto-rotation in QWebView      [Solved] PySide new Mac OS install can’t load QtCore.so ››

You must log in to post a reply. Not a member yet? Register here!