Problem with string -> int conversion ?

M

Madhusudan Singh

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
 
F

Fredrik Lundh

Madhusudan said:
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>
 
M

Madhusudan Singh

Fredrik Lundh wrote:

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 ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,266
Messages
2,571,318
Members
47,998
Latest member
GretaCjy4

Latest Threads

Top