11

When (and only when) I quit my application, these (and only these) repeated message appear on the command prompt:

QObject::startTimer: QTimer can only be used with threads started with QThread
QObject::startTimer: QTimer can only be used with threads started with QThread
QObject::startTimer: QTimer can only be used with threads started with QThread

This is quite strange for me, because I never use QTimer in my code (or QThread). In fact, no errors or crashes happen using the application, so this is not a real problem, actually. This happen in both Windows and Linux OSs.

All my imports:

from __future__ import print_function
from PyQt4.QtGui import (QApplication, QMainWindow,
                         QFileSystemModel, QTreeView, QTableView,
                         QAbstractItemView, QMenu, QAction, QKeyEvent)
from PyQt4.QtCore import QDir, Qt, SIGNAL, QString, QFileInfo, QCoreApplication
import sys

The main function:

def main():
    app = QApplication(sys.argv)
    app.setApplicationName("QFM")
    app.setStyle("plastique")
    gui = MainWindow()
    gui.show()
    app.exec_()

Perhaps it could be something related to QFileSystemWatcher (used by QFileSystemModel), I guess...maybe it uses some QTimer features.

iacopo
  • 663
  • 1
  • 7
  • 22
  • Can you point out on which line of your code these messages are caused? – Kai Nov 26 '12 at 10:12
  • Absolutely not, this 2 or 3 repeated lines are the unique information that are given to me!!! :-|. – iacopo Nov 26 '12 at 10:36
  • Try adding some console output to find the causing code line. – Kai Nov 26 '12 at 10:37
  • Maybe it comes from a library you use. Try to eliminate parts of your code until the problem goes away. That should give you some clue where the problem lies. – Janne Karila Nov 26 '12 at 12:42
  • @user714965: there is _no_ other console output, it's not possible to find the causing code line. JanneKarila: I added my imports. Because the application is still very small, I'm going to go test previous versions to find the moment when the issue started to appear. – iacopo Nov 26 '12 at 15:53
  • possible duplicate of [PyQt4 Results in QThread error](http://stackoverflow.com/questions/8995367/pyqt4-results-in-qthread-error) – ekhumoro Nov 26 '12 at 18:18
  • Without a SSCCE this question is basically impossible to evaluate. -1 – eric Dec 13 '15 at 18:14

3 Answers3

10

I've had similar problems in the past.

The QFileSystemModeldocumentation page says the following:

QFileSystemModel.__init__ (self, QObject parent = None)

The parent argument, if not None, causes self to be owned by Qt instead of PyQt.

Constructs a file system model with the given parent.

If you don't pass a parent argument then the Python garbage collector can delete the object at the wrong time and as a side effect raise the error you mention. My advise is to make sure that your objects have a proper parent. I think it should fix the problem.

PS: I haven't checked the docs for every class you use. Maybe QFileSystemModel is not the only class on which this thing happens.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Vicent
  • 5,322
  • 2
  • 28
  • 36
3

In my experience this happens when I subclass a Qt class and one of the members of the subclass is not part of the Qt hierarchy. For example:

class MainWindow(QMainWindow):
    def __init__(self, *args, **kwargs):
        super(MainWindow, self).__init__(*args, **kwargs)
        ...
        self.my_widget = MyWidget()
        ...

If I implement MyWidget in this way, it will give me the QTimer error when the object is destroyed:

class MyWidget(object):
    def __init__(self):
        # do stuff

However, if MyWidget inherits from QObject then no error occurs:

class MyWidget(QObject):
    def __init__(self, parent):
        super(MyWidget, self).__init__(parent)
        #do stuff
Kai
  • 2,482
  • 1
  • 19
  • 21
0

pass in self into the instantiation of it if you are not subclassing it like so QFileSystemModel(self)

icharis
  • 261
  • 2
  • 3