- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
首先,我是 python 和 pyside 的新手。
我有三个不同的 QTreeWidgets,代表三个不同的文件夹结构。当我尝试连续清除所有三个时,应用程序崩溃。
widgets = [ self.Delete_treeWidget01, self.Delete_treeWidget02, self.Delete_treeWidget03 ]
for widget in widgets:
widget.clear()
我也试过用其他方法清除它,例如
widgets = [ self.treeWidget01, self.treeWidget02, self.treeWidget03 ]
for widget in widgets:
aList = (range(widget.topLevelItemCount()))
for i in aList[::-1]:
widget.takeTopLevelItem(i)
这也使它以同样的方式崩溃。
我点击“调试”, Visual Studio 给了我这条信息:
Unhandled exception at 0x000000006E9D2C68 (QtGui4.dll) in mayapy.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.
(它说是 maya,因为我正在使用带有 maya python 解释器的 eclipse,因为我主要为 maya 编写代码。然而,这是独立的,不涉及 maya。)
我删除了 QTreeWidgets 所代表的层次结构中的一个文件夹,为了让它再次准确显示,我想清除它以便再次填充它。
当我用谷歌搜索这个问题时,有人说它与线程有关,但由于我是 python 和 pyside 的新手,我什至不知道如何线程。
有人知道如何做到这一点吗?
编辑:
代码
import os
import sys
from PySide import QtGui, QtCore
from Toolbox_Test_UI import Ui_MirrorFolderCreation
from PySide.QtGui import QMainWindow, QApplication
class MainWindow( QMainWindow, Ui_MirrorFolderCreation ):
def __init__( self ):
super( MainWindow, self ).__init__()
self.setupUi( self )
# Connects the buttons
self.Delete_pushButton01.clicked.connect( lambda: self.folderDialog( 'delete1_dir' ) )
self.Delete_pushButton02.clicked.connect( lambda: self.folderDialog( 'delete2_dir' ) )
self.Delete_pushButton03.clicked.connect( lambda: self.folderDialog( 'delete3_dir' ) )
self.Delete_deletePushButton.clicked.connect( lambda: self.deleteFolders() )
self.Delete_populatePushButton.clicked.connect( lambda: self.populateTreeViews() )
self.Delete_treeWidget01.itemClicked.connect( lambda: self.findMirroredItem() )
# Change resize mode
headers = [self.Delete_treeWidget01.header(), self.Delete_treeWidget02.header(), self.Delete_treeWidget03.header()]
for head in headers:
head.setResizeMode( 0, QtGui.QHeaderView.ResizeToContents )
def findMirroredItem( self ):
''' find a item mirrored in widget 2 and 3 '''
#self.deselectTreeWidgetsItem()
widgets = [self.Delete_treeWidget02, self.Delete_treeWidget03]
for eachWidget in widgets:
self.selectMirroredItems(eachWidget)
def folderDialog( self, arg ):
''' Set lineEdits'''
dialog = QtGui.QFileDialog()
path = dialog.getExistingDirectory( self, "Select Folder", os.getcwd() )
if path:
if arg == 'delete1_dir':
self.Delete_lineEdit01.setText( path )
elif arg == 'delete2_dir':
self.Delete_lineEdit02.setText( path )
elif arg == 'delete3_dir':
self.Delete_lineEdit03.setText( path )
def populateTreeViews(self):
''' poplute the widgets'''
widgets = { self.Delete_treeWidget01:self.Delete_lineEdit01, self.Delete_treeWidget02:self.Delete_lineEdit02, self.Delete_treeWidget03:self.Delete_lineEdit03 }
for treeWidget, lineEdit in widgets.iteritems():
folderPath = lineEdit.text()
if folderPath:
treeWidget.clear()
self.populateTreeWidgetSearch( treeWidget, folderPath )
def populateTreeWidgetSearch( self, treeWidget, folderPath ):
rootTreeView = None
def searchFolder( folder, rootTreeView ):
folders = os.listdir( folder )
for eachSubFolder in folders:
childFolder = os.path.join( folder, eachSubFolder )
if os.path.isdir( childFolder ):
if rootTreeView is None:
rootTreeView = treeWidget.invisibleRootItem()
item = QtGui.QTreeWidgetItem( rootTreeView )
item.setText( 0, eachSubFolder )
item.setExpanded( True )
item.parent()
treeWidget.addTopLevelItem( item )
if os.listdir( childFolder ):
searchFolder( childFolder, item )
if folderPath:
searchFolder( folderPath, rootTreeView )
def deleteFolders( self ):
def countFolder( folder):
folders = os.listdir( folder )
for eachSubFolder in folders:
eachSubFolder = os.path.join( folder, eachSubFolder )
if os.path.isdir( eachSubFolder ):
self.foIndex += 1
if os.listdir( eachSubFolder ):
countFolder( eachSubFolder)
else:
self.fiIndex += 1
def findFolders():
folderPath = []
widgets = {self.Delete_treeWidget01:self.Delete_lineEdit01, self.Delete_treeWidget02:self.Delete_lineEdit02, self.Delete_treeWidget03:self.Delete_lineEdit03}
for treeWidget, lineEdit in widgets.iteritems():
selectedItems = treeWidget.selectedItems()
for item in selectedItems:
basePath = lineEdit.text()
if basePath:
treeWidgetHierarchy = self.getTreePath( item )
folderPath.append( os.path.join( basePath, treeWidgetHierarchy ) )
return folderPath
infoDict = []
for eachFolder in findFolders():
self.fiIndex = 0
self.foIndex = 0
countFolder( eachFolder)
infoDict.append({'deletionFolder':eachFolder, 'files':self.fiIndex, 'folders':self.foIndex})
self.populateTreeViews()
def deselectTreeWidgetsItem(self):
# Deselect everything from previews selection
widgets = [self.Delete_treeWidget02, self.Delete_treeWidget03]
for eachWidget in widgets:
for eachSel in eachWidget.selectedItems():
eachSel.setSelected( False )
def selectMirroredItems(self, widget):
# Get selected item
item = self.Delete_treeWidget01.selectedItems()[0]
# Path to the selected item
itemChilds = self.getTreePath( item )
# Find all top items to iterate through
topItems = widget.findItems( itemChilds.split( '/' )[0],QtCore.Qt.MatchExactly,0 )
# Default state of variables
itemFound = None
listCheck = []
index = 1
if topItems:
TreeWidgetItems = QtGui.QTreeWidgetItemIterator( topItems[0] )
TreeWidgetItemList = self.remakeList( TreeWidgetItems )
for child in itemChilds.split( '/' ):
index = index + 1
for item in TreeWidgetItemList:
itemlist = self.getTreePath( item )
if child == item.text( 0 ):
listCheck.append( item.text( 0 ))
if ( itemlist in itemChilds ) and ( len( itemChilds.split('/')) < index ):
itemFound = item
if itemFound:
widget.scrollToItem(itemFound)
itemFound.setSelected( True )
def remakeList(self, treeWidgetList):
itemList = []
for it in treeWidgetList:
itemList.append(it.value())
return itemList
def getTreePath( self, item ):
path = []
while item is not None:
path.append( str( item.text( 0 )))
item = item.parent()
return '/'.join( reversed( path ))
if __name__ == '__main__':
app = QApplication( sys.argv )
frame = MainWindow()
frame.show()
app.exec_()
窗口:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'C:/Users/stmahe1/GoogleDrive_Group3/TA_SpaceShooter/scripts/WIP/mattias/PipelineToolbox/Mirror/ui/Toolbox_Test.ui'
#
# Created: Tue Apr 08 13:19:23 2014
# by: pyside-uic 0.2.15 running on PySide 1.2.1
#
# WARNING! All changes made in this file will be lost!
from PySide import QtCore, QtGui
class Ui_MirrorFolderCreation(object):
def setupUi(self, MirrorFolderCreation):
MirrorFolderCreation.setObjectName("MirrorFolderCreation")
MirrorFolderCreation.resize(807, 626)
self.centralwidget = QtGui.QWidget(MirrorFolderCreation)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayout_8 = QtGui.QVBoxLayout(self.centralwidget)
self.verticalLayout_8.setObjectName("verticalLayout_8")
self.verticalLayout_4 = QtGui.QVBoxLayout()
self.verticalLayout_4.setObjectName("verticalLayout_4")
self.label_6 = QtGui.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setFamily("Orator Std")
font.setPointSize(11)
font.setWeight(75)
font.setBold(True)
self.label_6.setFont(font)
self.label_6.setObjectName("label_6")
self.verticalLayout_4.addWidget(self.label_6)
self.horizontalLayout_4 = QtGui.QHBoxLayout()
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
self.verticalLayout_6 = QtGui.QVBoxLayout()
self.verticalLayout_6.setObjectName("verticalLayout_6")
self.horizontalLayout_20 = QtGui.QHBoxLayout()
self.horizontalLayout_20.setObjectName("horizontalLayout_20")
self.Delete_lineEdit01 = QtGui.QLineEdit(self.centralwidget)
self.Delete_lineEdit01.setObjectName("Delete_lineEdit01")
self.horizontalLayout_20.addWidget(self.Delete_lineEdit01)
self.Delete_pushButton01 = QtGui.QPushButton(self.centralwidget)
self.Delete_pushButton01.setMaximumSize(QtCore.QSize(30, 16777215))
self.Delete_pushButton01.setObjectName("Delete_pushButton01")
self.horizontalLayout_20.addWidget(self.Delete_pushButton01)
self.verticalLayout_6.addLayout(self.horizontalLayout_20)
self.Delete_treeWidget01 = QtGui.QTreeWidget(self.centralwidget)
self.Delete_treeWidget01.setEnabled(True)
self.Delete_treeWidget01.setObjectName("Delete_treeWidget01")
self.Delete_treeWidget01.header().setVisible(False)
self.Delete_treeWidget01.header().setStretchLastSection(False)
self.verticalLayout_6.addWidget(self.Delete_treeWidget01)
self.horizontalLayout_4.addLayout(self.verticalLayout_6)
self.verticalLayout_5 = QtGui.QVBoxLayout()
self.verticalLayout_5.setObjectName("verticalLayout_5")
self.horizontalLayout_19 = QtGui.QHBoxLayout()
self.horizontalLayout_19.setObjectName("horizontalLayout_19")
self.Delete_lineEdit02 = QtGui.QLineEdit(self.centralwidget)
self.Delete_lineEdit02.setObjectName("Delete_lineEdit02")
self.horizontalLayout_19.addWidget(self.Delete_lineEdit02)
self.Delete_pushButton02 = QtGui.QPushButton(self.centralwidget)
self.Delete_pushButton02.setMaximumSize(QtCore.QSize(30, 16777215))
self.Delete_pushButton02.setObjectName("Delete_pushButton02")
self.horizontalLayout_19.addWidget(self.Delete_pushButton02)
self.verticalLayout_5.addLayout(self.horizontalLayout_19)
self.Delete_treeWidget02 = QtGui.QTreeWidget(self.centralwidget)
self.Delete_treeWidget02.setObjectName("Delete_treeWidget02")
self.Delete_treeWidget02.headerItem().setText(0, "1")
self.Delete_treeWidget02.header().setVisible(False)
self.Delete_treeWidget02.header().setStretchLastSection(False)
self.verticalLayout_5.addWidget(self.Delete_treeWidget02)
self.horizontalLayout_4.addLayout(self.verticalLayout_5)
self.verticalLayout_7 = QtGui.QVBoxLayout()
self.verticalLayout_7.setObjectName("verticalLayout_7")
self.horizontalLayout_21 = QtGui.QHBoxLayout()
self.horizontalLayout_21.setObjectName("horizontalLayout_21")
self.Delete_lineEdit03 = QtGui.QLineEdit(self.centralwidget)
self.Delete_lineEdit03.setObjectName("Delete_lineEdit03")
self.horizontalLayout_21.addWidget(self.Delete_lineEdit03)
self.Delete_pushButton03 = QtGui.QPushButton(self.centralwidget)
self.Delete_pushButton03.setMaximumSize(QtCore.QSize(30, 16777215))
self.Delete_pushButton03.setObjectName("Delete_pushButton03")
self.horizontalLayout_21.addWidget(self.Delete_pushButton03)
self.verticalLayout_7.addLayout(self.horizontalLayout_21)
self.Delete_treeWidget03 = QtGui.QTreeWidget(self.centralwidget)
self.Delete_treeWidget03.setObjectName("Delete_treeWidget03")
self.Delete_treeWidget03.headerItem().setText(0, "1")
self.Delete_treeWidget03.header().setVisible(False)
self.verticalLayout_7.addWidget(self.Delete_treeWidget03)
self.horizontalLayout_4.addLayout(self.verticalLayout_7)
self.verticalLayout_4.addLayout(self.horizontalLayout_4)
self.horizontalLayout_5 = QtGui.QHBoxLayout()
self.horizontalLayout_5.setObjectName("horizontalLayout_5")
self.Delete_populatePushButton = QtGui.QPushButton(self.centralwidget)
self.Delete_populatePushButton.setObjectName("Delete_populatePushButton")
self.horizontalLayout_5.addWidget(self.Delete_populatePushButton)
spacerItem = QtGui.QSpacerItem(20, 20, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Minimum)
self.horizontalLayout_5.addItem(spacerItem)
self.Delete_deletePushButton = QtGui.QPushButton(self.centralwidget)
self.Delete_deletePushButton.setObjectName("Delete_deletePushButton")
self.horizontalLayout_5.addWidget(self.Delete_deletePushButton)
self.verticalLayout_4.addLayout(self.horizontalLayout_5)
self.verticalLayout_8.addLayout(self.verticalLayout_4)
self.gridLayout_4 = QtGui.QGridLayout()
self.gridLayout_4.setObjectName("gridLayout_4")
self.verticalLayout_8.addLayout(self.gridLayout_4)
MirrorFolderCreation.setCentralWidget(self.centralwidget)
self.actionExit = QtGui.QAction(MirrorFolderCreation)
self.actionExit.setObjectName("actionExit")
self.actionLoad_preset = QtGui.QAction(MirrorFolderCreation)
self.actionLoad_preset.setObjectName("actionLoad_preset")
self.actionSave_Preset = QtGui.QAction(MirrorFolderCreation)
self.actionSave_Preset.setObjectName("actionSave_Preset")
self.retranslateUi(MirrorFolderCreation)
QtCore.QMetaObject.connectSlotsByName(MirrorFolderCreation)
MirrorFolderCreation.setTabOrder(self.Delete_lineEdit01, self.Delete_lineEdit02)
MirrorFolderCreation.setTabOrder(self.Delete_lineEdit02, self.Delete_lineEdit03)
MirrorFolderCreation.setTabOrder(self.Delete_lineEdit03, self.Delete_pushButton01)
MirrorFolderCreation.setTabOrder(self.Delete_pushButton01, self.Delete_pushButton02)
MirrorFolderCreation.setTabOrder(self.Delete_pushButton02, self.Delete_pushButton03)
MirrorFolderCreation.setTabOrder(self.Delete_pushButton03, self.Delete_populatePushButton)
MirrorFolderCreation.setTabOrder(self.Delete_populatePushButton, self.Delete_deletePushButton)
MirrorFolderCreation.setTabOrder(self.Delete_deletePushButton, self.Delete_treeWidget01)
MirrorFolderCreation.setTabOrder(self.Delete_treeWidget01, self.Delete_treeWidget02)
MirrorFolderCreation.setTabOrder(self.Delete_treeWidget02, self.Delete_treeWidget03)
def retranslateUi(self, MirrorFolderCreation):
MirrorFolderCreation.setWindowTitle(QtGui.QApplication.translate("MirrorFolderCreation", "Technical Artist Toolbox", None, QtGui.QApplication.UnicodeUTF8))
self.label_6.setText(QtGui.QApplication.translate("MirrorFolderCreation", "Mirrored Deletion of Folders", None, QtGui.QApplication.UnicodeUTF8))
self.Delete_pushButton01.setText(QtGui.QApplication.translate("MirrorFolderCreation", "...", None, QtGui.QApplication.UnicodeUTF8))
self.Delete_pushButton02.setText(QtGui.QApplication.translate("MirrorFolderCreation", "...", None, QtGui.QApplication.UnicodeUTF8))
self.Delete_pushButton03.setText(QtGui.QApplication.translate("MirrorFolderCreation", "...", None, QtGui.QApplication.UnicodeUTF8))
self.Delete_populatePushButton.setText(QtGui.QApplication.translate("MirrorFolderCreation", "Update", None, QtGui.QApplication.UnicodeUTF8))
self.Delete_deletePushButton.setText(QtGui.QApplication.translate("MirrorFolderCreation", "Delete", None, QtGui.QApplication.UnicodeUTF8))
self.actionExit.setText(QtGui.QApplication.translate("MirrorFolderCreation", "Exit", None, QtGui.QApplication.UnicodeUTF8))
self.actionLoad_preset.setText(QtGui.QApplication.translate("MirrorFolderCreation", "Load Preset", None, QtGui.QApplication.UnicodeUTF8))
self.actionSave_Preset.setText(QtGui.QApplication.translate("MirrorFolderCreation", "Save Preset", None, QtGui.QApplication.UnicodeUTF8))
经过一些进一步的测试,这可能是因为我在小部件中选择了一些东西,(发现如果我不运行 findMirroredItem() 它会起作用)但是它无助于取消选择先取消选择所有内容。
如果我单击第一个小部件,它会尝试在其他两个小部件中选择一个相似的对象。如果我不点击第一个小部件,我可以重新加载/填充它多少次我想要它不会崩溃。如果我选择了一些东西,如果我尝试重新加载/填充它,它最终会崩溃。
最佳答案
这似乎是由 QTreeWidgetItemIterator
中的 PySide 错误引起的,当传递 QTreeWidgetItem
作为第一个参数时。当 QTreeWidget
作为第一个参数传递时,问题就消失了。等效的 PyQt4 代码不会出现此错误。
可以通过修改 selectMirroredItems
中的以下行来修复示例代码:
# TreeWidgetItems = QtGui.QTreeWidgetItemIterator( topItems[0] )
TreeWidgetItems = QtGui.QTreeWidgetItemIterator(widget)
似乎简单地遍历 QTreeWidgetItemIterator
就足以导致段错误(尽管我没有尝试创建最小测试用例)。
可以报告 PySide 错误 here .
关于python - PySide QTreeWidget clear() 导致崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22934043/
我正在尝试使用 Spark 从 Cassandra 读取数据。 DataFrame rdf = sqlContext.read().option("keyspace", "readypulse
这是代码: void i_log_ (int error, const char * file, int line, const char * fmt, ...) { /* Get erro
我必须调试一个严重依赖 Gtk 的程序。问题是由于某些原因,在使用 GtkWindow 对象时开始出现许多运行时警告。问题是,即使 Gtk 提示严重错误,它也不会因这些错误而中止。我没有代码库的更改历
我正在尝试从已有效编译和链接的程序中检索二进制文件。我已经通过 GL_PROGRAM_BINARY_LENGTH 收到了它的长度。该文档说有两个实例可能会发生 GL_INVALID_OPERATION
我有一个托管在 Azure 环境中的服务。我正在使用控制台应用程序使用该服务。这样做时,我得到了异常: "The requested service, 'http://xxxx-d.yyyy.be/S
我有以下代码,它被 SEGV 信号杀死。使用调试器表明它被 main() 中的第一个 sem_init() 杀死。如果我注释掉第一个 sem_init() ,第二个会导致同样的问题。我试图弄清楚是什么
目前我正在编写一个应用程序(目标 iOS 6,启用 ARC),它使用 JSON 进行数据传输,使用核心数据进行持久存储。 JSON 数据由 PHP 脚本通过 json_encode 从 MySQL 数
我对 Xamarin.Forms 还是很陌生。我在出现的主页上有一个非常简单的功能 async public Task BaseAppearing() { if (UserID
这是我的代码的简化版本。 public class MainActivity extends ActionBarActivity { private ArrayList entry = new Arr
我想弄明白为什么我的两个 Java 库很难很好地协同工作。这是场景: 库 1 有一个类 A,其构造函数如下: public A(Object obj) { /* boilerplate */ } 在以
如果网站不需要身份验证,我的代码可以正常工作,如果需要,则在打印“已创建凭据”后会立即出现 EXC_BAD_ACCESS 错误。我不会发布任何内容,并且此代码是直接从文档中复制的 - 知道出了什么问题
我在使用 NSArray 填充 UITableView 时遇到问题。我确信我正在做一些愚蠢的事情,但我无法弄清楚。当我尝试进行简单的计数时,我得到了 EXC_BAD_ACCESS,我知道这是因为我试图
我在 UITableViewCell 上有一个 UITextField,在另一个单元格上有一个按钮。 我单击 UITextField(出现键盘)。 UITextField 调用了以下方法: - (BO
我有一个应用程序出现间歇性崩溃。崩溃日志显示了一个堆栈跟踪,这对我来说很难破译,因此希望其他人看到了这一点并能为我指出正确的方向。 基本上,应用程序在启动时执行反向地理编码请求,以在标签中显示用户的位
我开发了一个 CGImage,当程序使用以下命令将其显示在屏幕上时它工作正常: [output_view.layer performSelectorOnMainThread:@selector(set
我正在使用新的 EncryptedSharedPreferences以谷歌推荐的方式上课: private fun securePrefs(context: Context): SharedPrefe
我有一个中继器,里面有一些控件,其中一个是文本框。我正在尝试使用 jquery 获取文本框,我的代码如下所示: $("#").click(function (event) {}); 但我总是得到 nu
在以下场景中观察到 TTS 初始化错误,太随机了。 已安装 TTS 引擎,存在语音集,并且可以从辅助功能选项中播放示例 tts。 TTS 初始化在之前初始化和播放的同一设备上随机失败。 在不同的设备(
maven pom.xml org.openjdk.jol jol-core 0.10 Java 类: public class MyObjectData { pr
在不担心冲突的情况下,可以使用 MD5 作为哈希值,字符串长度最多为多少? 这可能是通过为特定字符集中的每个可能的字符串生成 MD5 哈希来计算的,长度不断增加,直到哈希第二次出现(冲突)。没有冲突的
我是一名优秀的程序员,十分优秀!