0

我给了模型一个父模型,但是退出时它仍然显示错误消息,下面的代码出了什么问题

#!/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)

图像

4

1 回答 1

1

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

self.setAttribute(Qt.WA_DeleteOnClose)
于 2016-09-03T21:53:50.990 回答