title: How can I use a QDateTime inside a Thread?
body: <p>I have a thread where I need to execute a heavy function. </p>
  
  <p>First, I have a function that takes two <code>QDateTime</code> values from the GUI and convert them to UNIX timestamps. Secondly, the "heavy" function uses these values to perform a task.</p>
  
  <p>Both functions <code>(function_task, time_converter_to_unix)</code> do not belong to any class, so as far as I know I can use them in the thread.</p>
  
  <p>But not the parameters, since I cannot access the <code>QDateTime</code> values.</p>
  
  <blockquote>
    <p><em>Error: AttributeError: 'TaskThread' object has no attribute 'startTime'</em></p>
  </blockquote>
  
  <p>How can I access the <code>QDateTime</code> and read the content from the thread? Thank you.</p>
  
  <p><strong>EDIT:</strong> Complete Code. You can find also the link to the GUI in the following link: <a href="https://drive.google.com/folderview?id=1siYGyHag9Qio3PUGvUrGXi9vufKDzdvJ" rel="nofollow noreferrer">interface.ui</a></p>
  
  <pre><code>import sys
  import datetime
  import time
  
  from PyQt4 import QtCore, QtGui, uic
  from PyQt4.QtCore import *
  from PyQt4.QtGui import *
  
  # Link to GUI
  qtCreatorFile = "interface.ui"
  
  Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile)
  
  def time_converter_to_unix(start_datetime, end_datetime):
      # Convert QTimeEdit to UNIX Timestamp (int, msec included), and then to float
      start_datetime_unix_int = start_datetime.toMSecsSinceEpoch ()
      start_datetime_unix = (float(start_datetime_unix_int) / 1000)
  
      end_datetime_unix_int = end_datetime.toMSecsSinceEpoch ()
      end_datetime_unix = (float(end_datetime_unix_int) / 1000)
  
      return start_datetime_unix, end_datetime_unix
  
  def dummy_function(self, start_datetime_unix, end_datetime_unix): 
      # Dummy function, just to simulate a task 
      result = start_datetime_unix + end_datetime_unix 
      print result    
  
  class Tool(QtGui.QMainWindow, Ui_MainWindow):
      def __init__(self, parent = None):
  
          # Setting-ip UI
          QtGui.QMainWindow.__init__(self)
          Ui_MainWindow.__init__(self)
          self.setupUi(self)
  
          # Button Action
          self.runButton.clicked.connect(self.onStart)
  
          # Progress Bar and Label. At the begining, the bar is at 0
          self.progressBar.setValue(0)
          self.progressBar.setRange(0,100)
          self.resultLabel.setText("Waiting...")  
  
          #Thread
          self.myLongTask = TaskThread()
          self.myLongTask.taskFinished.connect(self.onFinished)        
  
      def onStart(self):      
          # Before running the thread, we set the progress bar in waiting mode
          self.progressBar.setRange(0,0)
          self.resultLabel.setText("In progress...")  
  
          print "Starting thread..."
          self.myLongTask.start()
  
      def onFinished(self):
          # Stop the pulsation when the thread has finished
          self.progressBar.setRange(0,1)
          self.progressBar.setValue(1)
          self.resultLabel.setText("Done")  
  
  class TaskThread(QtCore.QThread):  
      taskFinished = QtCore.pyqtSignal()
  
      def __init__(self):
          QtCore.QThread.__init__(self)
  
      def __del__(self):
          self.wait()
  
      def run(self):  
          # First, we read the times from the QDateTime elements in the interface      
          print "Getting times..."
          start_datetime_unix, end_datetime_unix = time_converter_to_unix(self.startTime.dateTime(), self.endTime.dateTime())
  
          # Then, we put these values in my_function
          print "Executing function..."
          dummy_function(self, start_datetime_unix, end_datetime_unix) 
  
          # To finish, we execute onFinished.
          print "Finishing thread..."
          self.taskFinished.emit()
  
  def main():
      app = QtGui.QApplication(sys.argv)
      window = Tool()
      window.show()
      sys.exit(app.exec_())
  
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p>If you execute it along with the .ui, you will see, that once we click on "Run", the Progress bar stays in waiting mode, and the error commented above appears.</p>