By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,931 Members | 2,015 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,931 IT Pros & Developers. It's quick & easy.

Problem with string -> int conversion ?

P: n/a
Hi

I am working with an application that I designed with the Designer > pyuic
workflow and I get the following error on trying to process the contents of
a combobox :
Traceback (most recent call last):
File "measure.py", line 908, in acquiredata
np=self.getNPrange()
File "measure.py", line 1167, in getNPrange
signalrange=int(signalrangestr)
TypeError: int() argument must be a string or a number

The code is :

void Form3::getNPrange()
{
signalrangestr=self.NPcombobox.currentText()
signalrange=int(signalrangestr)
if globaldebug : print 'NP Signal range = ',signalrange
return signalrange
}

The contents of the combobox are strings representing numbers in the range
[0,6].

Isn't signalrangestr above a string ? Or at the very least, a number. I
entered these numbers myself in designer, so they do not have any
white-space (len(signalrangestr) returns 1). In any case, an attempt to use
strip() fails with :

Traceback (most recent call last):
File "measure.py", line 908, in acquiredata
np=self.getNPrange()
File "measure.py", line 1169, in getNPrange
signalrange=int(signalrangestr.strip())
AttributeError: strip

Aug 30 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Madhusudan Singh wrote:
I am working with an application that I designed with the Designer > pyuic
workflow and I get the following error on trying to process the contents
of
a combobox :

Traceback (most recent call last):
File "measure.py", line 908, in acquiredata
np=self.getNPrange()
File "measure.py", line 1167, in getNPrange
signalrange=int(signalrangestr)
TypeError: int() argument must be a string or a number

The code is :

void Form3::getNPrange()
{
what language is this?
signalrangestr=self.NPcombobox.currentText()
signalrange=int(signalrangestr)
if globaldebug : print 'NP Signal range = ',signalrange
return signalrange
} Isn't signalrangestr above a string ? Or at the very least, a number.


if the callback code is Python, you should be able to add a print
statement to the line just before the failing "int" call:

print repr(signalrangestr), type(signalrangestr)
signalrange = int(signalrangestr)

that print statement should be all you need to figure out what
signalrangestr really is.

</F>

Aug 30 '05 #2

P: n/a
Fredrik Lundh wrote:

The code is :

void Form3::getNPrange()
{
what language is this?


Its python embedded in the designer workflow. pyuic extracts stuff from it,
and generates a python script from the ui.h file.

if the callback code is Python, you should be able to add a print
statement to the line just before the failing "int" call:

print repr(signalrangestr), type(signalrangestr)
signalrange = int(signalrangestr)

that print statement should be all you need to figure out what
signalrangestr really is.


Thanks for the hint.

I get :

<__main__.qt.QString object at 0xb7c1a3ec> <class '__main__.qt.QString'>

The question is :

How do I convert a QString to a plain string ?
Aug 31 '05 #3

P: n/a
Madhusudan Singh wrote:
if the callback code is Python, you should be able to add a print
statement to the line just before the failing "int" call:

print repr(signalrangestr), type(signalrangestr)
signalrange = int(signalrangestr)

that print statement should be all you need to figure out what
signalrangestr really is.


Thanks for the hint.

I get :

<__main__.qt.QString object at 0xb7c1a3ec> <class '__main__.qt.QString'>

The question is :

How do I convert a QString to a plain string ?


googling for "pyqt qstring" brought up this page:

http://www.opendocspublishing.com/pyqt/x2068.htm

</F>

Aug 31 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.