2016-09-03 78 views
0

我已經給模型中的父母,但它仍然顯示錯誤消息退出時,什麼時候退出是錯在下面的代碼QObject :: startTimer:QTimer只能用於用QThread啓動的線程嗎?

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

回答

0

,它並不會報錯了再

self.setAttribute(Qt.WA_DeleteOnClose) 
相關問題