from PyQt5 import QtCore timer = QtCore.QElapsedTimer() timer.start() # Some code execution elapsed_time = timer.elapsed() print(f"Elapsed time: {elapsed_time} microseconds")
from PyQt5.QtCore import QObject, pyqtSignal, QElapsedTimer class MyObject(QObject): elapsed_timer = pyqtSignal(int) def __init__(self): super().__init__() def run(self): # Some code execution self.elapsed_timer.emit(self.get_elapsed_time()) def get_elapsed_time(self) -> int: timer = QElapsedTimer() timer.start() # Some code execution return timer.elapsed()In this example, the elapsed_timer signal is emitted with the elapsed time in microseconds as the argument. The MyObject object can be connected to a slot that can receive the elapsed time signal and use it accordingly. Conclusion: In conclusion, QtCore QElapsedTimer is a useful feature provided by the PyQt5 package library that can help measure the elapsed time of specific code execution. It is an easy-to-use functionality that can be integrated into your Python applications quite easily.