0

I am building my first GUI in pyQT5 and I am pretty new to Python programming.

I am trying to use a set a Variable in one Qthread and using it in another. I figured that pyqtsignal was the way to do it. But i can't get it to work.

class GetCurrentSpeed(QThread):
    gpsLatSig = pyqtSignal(str)

    def __init__(self):
        QThread.__init__(self)

    def __del__(self):
        self.wait()

    def run(self):
        while True:
            ####Print a value in lon and lat so that its never empty
                lon = "18"
                lat = "59"

            ###Get Current Latitude and Longitude
                if report['class'] == 'TPV':
                            if hasattr(report, 'lat'):
                                lat = (str(report.lat))
                                self.gpsLatSig.emit(lat)
                            else:
                                lat = "59"
                                print("No GPS Lock")
                                self.gpsLatSig.emit(lat)

class PosSignals(QObject):
    GetGps = GetCurrentSpeed()

    def connectsig(self):
        self.GetGps.gpsLatSig[str].connect(self.handle_string)

    @pyqtSlot(str)
    def handle_string(self, text):
        print text

class OverPassApi(QThread):
    GetGps = GetCurrentSpeed()


    def __init__(self):
        QThread.__init__(self)
        self.b = PosSignals()


    def __del__(self):
        self.wait()

    def run(self):
        while True:
                self.b.connectsig()
                print b.handle_string()

                api = overpy.Overpass()
                result = api.query("""<osm-script>
                <query type="way">
                        <around lat="%s" lon="%s" radius="30"/>
                        <has-kv k="name" v=""/>
                    </query>
                    <print/>
                </osm-script>""" % (b.handle_string, 18))

This is just a part of the program and this might contain other errors since i have worked hard to get this to work.

My Issue is that I get the output "<main.PosSignals object at 0x72f0c210>" when i try to print the text in the handle function when i remove self like:

@pyqtSlot(str)
    def handle_string(text):
        print text

and when I keep self I need to provide an argument to the print b.handle_string() which then ofcourse only prints the argument I add.

What I want to achieve is to use the lat variable created in GetCurrentSpeed(QThread): and use it in class OverPassApi(QThread):

Chanda Korat
  • 2,453
  • 2
  • 19
  • 23

1 Answers1

0

Looks like you simply forgot a self argument for handle_string.

The Compiler
  • 11,126
  • 4
  • 40
  • 54