解决PyQt错误(QObject::startTimer: QTimer can only be used with threads started with QThread)
来源:互联网 发布:河南奔驰网络办公平台 编辑:程序博客网 时间:2024/06/05 13:07
近日在PyQt使用Model时,发现如果Model创建时未设置Parent,则运行完退出时会报错:
QObject::startTimer: QTimer can only be used with threads started with QThread
解决方法也很简单,创建Model时加上Parent即可。关于这个问题的原因及解决方案可以查看链接:PyQt QTimer problem {FIXED}。
测试代码如下:
#coding=utf-8from PyQt4.QtCore import *from PyQt4.QtGui import *if __name__ == '__main__': import sys app = QApplication(sys.argv) table = QTableView() model = QStandardItemModel(3, 3) # 改为 model = QStandardItemModel(3, 3, table) 即可避免错误 table.setModel(model) model.setHorizontalHeaderLabels(['Name', 'Height', 'Weight']) model.setData(model.index(0, 0, QModelIndex()), QVariant(u'松鼠')) model.setData(model.index(0, 1, QModelIndex()), QVariant(u'80cm')) model.setData(model.index(0, 2, QModelIndex()), QVariant(u'12Kg')) model.setData(model.index(1, 0, QModelIndex()), QVariant(u'树袋熊')) table.setGeometry(80, 20, 400, 300) table.setWindowTitle('Grid + Table Testing') table.show() sys.exit(app.exec_())
转载于:http://dreamisx.blog.163.com/blog/static/115004839201291224117107/
阅读全文
0 0
- 解决PyQt错误(QObject::startTimer: QTimer can only be used with threads started with QThread)
- QT “Timers can only be used with threads started with QThread”的解决办法~
- android编译错误之“Hardware acceleration can only be used with a single UI thread”,硬件加速
- A TextureView or a subclass can only be used with hardware acceleration enabled.错误原因分析
- @Field parameters can only be used with form encoding
- @Field parameters can only be used with form encoding
- python "threads can only be started once"解决方法
- java.lang.IllegalStateException: ActionBarContextView can only be used with android:layout_width="
- ActionBarImpl can only be used with a compatible window decor layout
- <merge /> can be used only with a valid ViewGroup root and attachToRoot=true
- java.lang.IllegalStateException: ActionBarImpl can only be used with a compatible window decor layou
- java.lang.IllegalStateException: ActionBarImpl can only be used with a compatible window decor layou
- java.lang.IllegalStateException: Hardware acceleration can only be used with a single UI thread.
- android.view.InflateException: <merge /> can be used only with a valid ViewGroup root and attachToRo
- Calling latest() can only be used in combination with key(String) and keyLike(String)
- <merge /> can be used only with a valid ViewGroup root and attachToRoot=true
- Hardware acceleration can only be used with a single UI thread
- -pie can only be used when targeting iOS 4.2 or later错误解决
- 提权
- linux命令常用合集,提权(转)
- WordPress 提示"在裁剪您的图像时发生了错误"解决方案
- docker容器之间共享目录
- What makes for effective detection proposals?
- 解决PyQt错误(QObject::startTimer: QTimer can only be used with threads started with QThread)
- web.xml配置文件详解
- 微信App iOS客户端不同阶段的发展策略
- Java设计模式——外观模式
- CentOS7 正则表达式-egrep,sed,awk
- dreamweaver快捷键
- 最短路径 Dijkstra
- Go Json序列化和反序列化
- Jmeter登录接口压测