PySide Bugzilla Closed for New Bugs

PySide is now a Qt Add-on and uses the Qt Project's JIRA Bug Tracker instead of this Bugzilla instance. This Bugzilla is left for reference purposes.

Bug 345 - Reading QSettings value set with PyQt4 binding always return a unicode with PySide
: Reading QSettings value set with PyQt4 binding always return a unicode with P...
Status: CLOSED INVALID
Product: PySide
Classification: Unclassified
Component: QtCore
: 0.4.0
: All All
: P3 normal
Assigned To: renato filho
:
:
:
  Show dependency treegraph
 
Reported: 2010-09-07 04:21 EEST by Benoît HERVIER
Modified: 2010-11-09 13:25 EET (History)
9 users (show)

See Also:


Attachments
Read Value (Pyside) (641 bytes, text/x-python)
2010-09-07 04:21 EEST, Benoît HERVIER
Details
Create value (PyQt4) (777 bytes, text/x-python)
2010-09-07 04:21 EEST, Benoît HERVIER
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Benoît HERVIER 2010-09-07 04:21:08 EEST
Created attachment 81 [details]
Read Value (Pyside)

Context :

Create QSettings value with PyQt4 binding. And then try to read them with
Pyside binding. You ll always get a unicode type.

To reproduce it launch the simple script : test_case_qsettings_pyqt4.py
And then launch the second simple script : test_case_qsettings_pyside.py

The expected results on first script is : 
string :  <class 'PyQt4.QtCore.QString'>
int :  <type 'int'>
bool : <type 'bool'>

The expected results on the second script is :
string :  <class 'unicode'>
int :  <type 'int'>
bool : <type 'bool'>

But the second script return : 
string :  <type 'unicode'>
int :  <type 'unicode'>
bool :  <type 'unicode'>
Comment 1 Benoît HERVIER 2010-09-07 04:21:33 EEST
Created attachment 82 [details]
Create value (PyQt4)
Comment 2 Hugo Parente Lima 2010-09-08 11:36:32 EEST
PySide is uses something equivalent to PyQt4 API2, so it doesn't have QString
or QVariant and all Qt methods which used to return a QString returns an
unicode object in PySide.
Comment 3 Hugo Parente Lima 2010-09-08 11:45:07 EEST
To prove what I said, if you run this code:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os

import sip
sip.setapi('QVariant', 2)
sip.setapi('QSettings', 2)
sip.setapi('QString', 2)

from PyQt4.QtCore import QSettings
from PyQt4.QtGui import QApplication

app = QApplication(sys.argv)
app.setOrganizationName("Khertan Software")
app.setOrganizationDomain("khertan.net")
app.setApplicationName("TestCase")

settings = QSettings()

print 'string : ',type(settings.value('testString'))
print 'int : ',type(settings.value('testInt'))
print 'bool : ',type(settings.value('testBool'))

You will get the same values as in PySide.
Comment 4 Benoît HERVIER 2010-09-08 12:11:30 EEST
So if i understood you well everything in QSetting is unicode ?

i know that everythings that Return QString in API1 return unicode in API2. But
here we should got an unicode, a int and a bool, not three unicode.
Comment 5 Hugo Parente Lima 2010-09-08 13:25:18 EEST
(In reply to comment #4)
> So if i understood you well everything in QSetting is unicode ?
> 
> i know that everythings that Return QString in API1 return unicode in API2. But
> here we should got an unicode, a int and a bool, not three unicode.

The value() method of QSettings returns a QVariant in C++, a QVariant holding a
QString because QSettings doesn't store the variable type, just the value, so
when PySide and PyQt see this QVariant they will try to transform it into the
value it's holding, a QString, then transform the QString into a unicode.

In other words, yes, you need to cast it yourself to int, bool, etc.
Comment 6 Benoît HERVIER 2010-09-11 08:37:40 EEST
Thanks for taking time to explain.
Comment 7 Matti Airas 2010-11-09 09:45:47 EET
*** Bug 459 has been marked as a duplicate of this bug. ***
Comment 8 Hugo Parente Lima 2010-11-09 13:25:16 EET
*** Bug 459 has been marked as a duplicate of this bug. ***