如何使用 PyQt4 将 QListWidjet 内容保存到 QSetting 或从 QSetting 加载 QListWidjet 内容?
我的 PyQt4 应用程序中有一个 QListWidget 。它包含文件夹路径。 我想将其内容保存到 QSettings 并稍后加载它们。 我使用这段代码来执行此操作:
def foldersSave(self):
folders = {} '''create dict to store data'''
foldersnum = self.configDialog.FolderLIST.count() '''get number of items'''
if foldersnum:
for i in range(foldersnum):
folders[i] = self.configDialog.FolderLIST.item(i).text() '''save items text to dict'''
return str(folders) '''return string of folders to store in QSettings'''
return None
但是如果我这样做,文件夹路径将存储在配置文件中,例如:
musicfolders={0: PyQt4.QtCore.QString(u'/home/sam/Ubuntu One')}
所以我不知道如何加载它们。我已经在不同的变体中尝试过类似的方法:
def foldersLoad(self):
folders = eval(self.tunSettings.value('musicfolders').toString())
它返回错误:
TypeError: eval() arg 1 must be a string or code object
看起来我只需要以其他方式保存数据,然后我现在就这样做。 查了很多,但没有任何线索。我确信答案是微不足道的,但我被困住了。
I've got a QListWidget in my PyQt4 app. It contains folders paths.
I want to save its contents to QSettings and load them later.
I used this code to do this:
def foldersSave(self):
folders = {} '''create dict to store data'''
foldersnum = self.configDialog.FolderLIST.count() '''get number of items'''
if foldersnum:
for i in range(foldersnum):
folders[i] = self.configDialog.FolderLIST.item(i).text() '''save items text to dict'''
return str(folders) '''return string of folders to store in QSettings'''
return None
But if I make so folders paths are stored in config file like:
musicfolders={0: PyQt4.QtCore.QString(u'/home/sam/Ubuntu One')}
So I have no idea how to load them then. I've tryed something like this in different variants:
def foldersLoad(self):
folders = eval(self.tunSettings.value('musicfolders').toString())
It returns error:
TypeError: eval() arg 1 must be a string or code object
It looks like I just need to save data some other way then I do now.
Gooled a lot, but have no clue. I'm sure the answer is trivial, but I'm stuck.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方案非常简单。我要使用 QStringList。
并加载
The solution is very simply. I were to use QStringList.
and load