Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyQt4 Results in QThread error

Using PyQt4 4.8.6 the code below produces the error

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

when a is used as the variable for QApplication, but it does not produce the error if cpp (or most anything else) is used for the variable. Is this a bug in PyQt4 or is there something I am missing?

#! /usr/bin/env python

# This is only needed for Python v2 but is harmless for Python v3.
import sip
sip.setapi('QVariant', 2)

from PyQt4 import QtGui

#def main():

if __name__ == '__main__':
    import sys

    if len(sys.argv) > 1:
       use_a = False
       print "Don't use a"
    else:
       use_a = True
       print "Use a"

    if use_a:
       a = QtGui.QApplication(sys.argv)
    else:
       cpp = QtGui.QApplication(sys.argv)

    model = QtGui.QStandardItemModel(4,2)
    tableView = QtGui.QTableView()
    tableView.setModel(model)

    tableView.show()
    if use_a:
       sys.exit(a.exec_())
    else:
       sys.exit(cpp.exec_())


#if __name__ == '__main__':
#  main()
like image 416
MES Avatar asked Jan 24 '12 22:01

MES


1 Answers

It is probably not a bug, as such.

When the Python begins to shut down, the order in which objects get garbage-collected can be unpredictable. The error message you are seeing is most likely a side-effect of that.

Is this causing a real problem in your application?

If not, just rename as appropriate and forget about it...

like image 90
ekhumoro Avatar answered Oct 23 '22 07:10

ekhumoro