Results 1 to 3 of 3

Thread: QTimer Not Firing, very strange...

  1. #1
    Join Date
    Apr 2015
    Posts
    11
    Qt products
    Qt5
    Platforms
    Windows

    Cool QTimer Not Firing, very strange...



    Qt Code:
    1. from PyQt5.QtCore import QObject, QTimer, pyqtSignal
    2. from urllib import request
    3. import xml.etree.ElementTree as ET
    4. from datetime import datetime, time
    5.  
    6. class SignalSource(QObject):
    7. valuesChecked = pyqtSignal(dict)
    8.  
    9. def __init__(self, xmlUrl, timerIntervalMs=10):
    10. QObject.__init__(self)
    11. self.xmlUrl = xmlUrl
    12. self.timer = QTimer()
    13. self.timer.setInterval(timerIntervalMs)
    14. self.timer.timeout.connect(self.timerFires)
    15. self.timer.start()
    16.  
    17. self.sample = {}
    18.  
    19. def getSample(self, sourcePiece):
    20. return self.sample[sourcePiece[0], sourcePiece[1]]
    21.  
    22. def timerFires(self):
    23. response = request.urlopen(self.xmlUrl)
    24. xmlStr = response.read()
    25. root = ET.fromstring(xmlStr)
    26.  
    27. for child in root:
    28. asset = child.attrib["Symbol"]
    29. self.sample[asset] = {
    30. "bid": float(child.find("Bid").text),
    31. "ask": float(child.find("Ask").text),
    32. "high": float(child.find("High").text),
    33. "low": float(child.find("Low").text),
    34. "@ last": time(child.find("Last").text),
    35. "direction": int(child.find("Direction").text),
    36. }
    37. self.valuesChecked.emit(self.sample)
    To copy to clipboard, switch view to plain text mode 

    I simply call
    signalSource = SignalSource("myXmlUrl")
    inside the main debug module at module scope.

    No timer firing action, so I never get to take a sample :'(

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTimer Not Firing, very strange...

    Is the event loop running?

    Cheers,
    _

  3. #3
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTimer Not Firing, very strange...

    What does your main program do after the line
    Qt Code:
    1. signalSource = SignalSource("myXmlUrl")
    To copy to clipboard, switch view to plain text mode 
    ? You need to run an event loop to receive timer events.

Similar Threads

  1. Strange QTimer behaviour in multithreaded system
    By sysmaniac in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 19th August 2011, 14:19
  2. Replies: 0
    Last Post: 15th April 2011, 16:26
  3. QFutureWatcher signals not firing
    By nwest in forum Newbie
    Replies: 5
    Last Post: 3rd December 2010, 23:56
  4. QT VS C++ 2005, QPushButton NOT FIRING!!!!!
    By harleyskater in forum General Programming
    Replies: 20
    Last Post: 12th June 2010, 03:15
  5. Strange inconsistency with QTimer
    By starlon in forum Qt Programming
    Replies: 2
    Last Post: 23rd October 2009, 07:57

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.