Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #83250 > unrolled thread
| Started by | Suhail Mahmood <suhailmahmood.c070@gmail.com> |
|---|---|
| First post | 2015-01-05 10:04 -0800 |
| Last post | 2015-01-06 08:40 +1100 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
toStringList in PyQt5 Suhail Mahmood <suhailmahmood.c070@gmail.com> - 2015-01-05 10:04 -0800
Re: toStringList in PyQt5 Chris Angelico <rosuav@gmail.com> - 2015-01-06 08:40 +1100
| From | Suhail Mahmood <suhailmahmood.c070@gmail.com> |
|---|---|
| Date | 2015-01-05 10:04 -0800 |
| Subject | toStringList in PyQt5 |
| Message-ID | <fab6a2bc-051f-42fa-a0f0-4dd6d6d87752@googlegroups.com> |
I was following the examples in 'Rapid GUI Development with Python and Qt' by Mark Summerfield. Sadly I am using PyQt5 and all the examples in this book are for PyQt4. But I have converted the codes to PyQt5 codes. But still I am having some problems. In chapter 6, there is something called QString, which I can't import(I guess this is more available in Pyqt5). Also, there is QSettings, returning something in by using
settings.value("Recent files").toStringList()
where settings is an instance of QSettings. Now as I can't import QString, this line is giving me an error like this:
self.recentFiles = settings.value("RecentFiles").toStringList()
AttributeError: 'NoneType' object has no attribute 'toStringList'
How can I get around with this problem?
Thanks.
[toc] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2015-01-06 08:40 +1100 |
| Message-ID | <mailman.17404.1420494034.18130.python-list@python.org> |
| In reply to | #83250 |
On Tue, Jan 6, 2015 at 5:04 AM, Suhail Mahmood
<suhailmahmood.c070@gmail.com> wrote:
> self.recentFiles = settings.value("RecentFiles").toStringList()
> AttributeError: 'NoneType' object has no attribute 'toStringList'
This sounds to me like your RecentFiles setting doesn't exist yet. You
could try a two-step approach:
files = settings.value("RecentFiles")
if files: self.recentFiles = files.toStringList()
# else self.recentFiles = ... something else? ...
or you could look at the docs for your QSettings object and see if you
can provide a default for it to return. That might save you some
trouble.
ChrisA
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web