QObject :: startTimer:QTimer只能用于以QThread启动的线程?

时间:2016-09-03 07:22:29

标签: python qt pyqt qcompleter

我已经为模型提供了父模型,但在退出时仍显示错误消息,以下代码中出现了错误

#!/usr/bin/env python2
import os
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4 import uic

import re

CODE = 'xxx'


class MyWindow(QDialog):

    def __init__(self, parent=None):
        super(MyWindow, self).__init__(parent)
        layout = QVBoxLayout(self)
        textedit = QTextEdit(self)

        textedit.setPlainText(CODE)
        layout.addWidget(textedit)
        self.setLayout(layout)

        self.resize(640, 280)

        self.lineedit = QLineEdit(self)
        self.lineedit.setGeometry(200, 12, 200, 32)

        self.completer = QCompleter(self)

        model = QStringListModel(self)
        model.setStringList(['1','2','3','4'])
        self.completer.setModel(model)
        self.lineedit.setCompleter(self.completer)

def main():

    app = QApplication(sys.argv)
    win = MyWindow()
    win.show()
    sys.exit(app.exec_())

if __name__ == "__main__":
    main()

退出时上述代码出错。

$ python2.7 ./ask_keep_completer0.py
QObject::startTimer: QTimer can only be used with threads started with QThread
Segmentation fault (core dumped)

img

1 个答案:

答案 0 :(得分:0)

添加此调用后,它不会再出错

self.setAttribute(Qt.WA_DeleteOnClose)