Qt-interest Archive, April 2008
QStringList question
Message 1 in thread
Hi all,
maybe this is a novice question, but it's got me scratching my head. I want to
store and retrieve a small list of values and I thought QStringList would be
good. So I declared the variable in the class header...
QStringList somevar;
My assumption was that when I inialize it that it would be both global and
persistent so inside one function...
QStringList somevar;
somevar.append("one")
somevar.append("two")
and inside another function of the same class I want to extract that list...
return somevar.join("\n")
Should that work? Not only do I not see any output, but I experimented with
every variation I could think of with no success. I can't seem to find any
documention and virtually every example I've seen is entirely local from
declaration to output inside a function. It seems like if you can decalare it
outside the function and use it inside without errors it should be working,
right?
--
[ signature omitted ]
Message 2 in thread
On Friday 25 April 2008 23:46:31 Eric Laffoon wrote:
> Hi all,
> maybe this is a novice question, but it's got me scratching my head. I want
> to store and retrieve a small list of values and I thought QStringList
> would be good. So I declared the variable in the class header...
> QStringList somevar;
> My assumption was that when I inialize it that it would be both global and
> persistent so inside one function...
***> QStringList somevar;
> somevar.append("one")
> somevar.append("two")
> and inside another function of the same class I want to extract that
> list... return somevar.join("\n")
>
> Should that work? Not only do I not see any output, but I experimented with
> every variation I could think of with no success. I can't seem to find any
> documention and virtually every example I've seen is entirely local from
> declaration to output inside a function. It seems like if you can decalare
> it outside the function and use it inside without errors it should be
> working, right?
You appear to be defining a (second) local somevar inside the first function.
This will disappear at the end of the first function and so your (first)
class member somevar never gets initialised. Try taking the line I've marked
*** above out.
HTH
Nick
--
[ signature omitted ]
Message 3 in thread
You probably want something like this in the header:
extern QStringList somevar;
and then have the instance at global scope in the source file, and
absolutely no declaration of it inside the function. Assuming I
understood you correctly.
Sincerely,
Marius K.
Eric Laffoon wrote:
> Hi all,
> maybe this is a novice question, but it's got me scratching my head. I want to
> store and retrieve a small list of values and I thought QStringList would be
> good. So I declared the variable in the class header...
> QStringList somevar;
> My assumption was that when I inialize it that it would be both global and
> persistent so inside one function...
> QStringList somevar;
> somevar.append("one")
> somevar.append("two")
> and inside another function of the same class I want to extract that list...
> return somevar.join("\n")
>
> Should that work? Not only do I not see any output, but I experimented with
> every variation I could think of with no success. I can't seem to find any
> documention and virtually every example I've seen is entirely local from
> declaration to output inside a function. It seems like if you can decalare it
> outside the function and use it inside without errors it should be working,
> right?
>
--
[ signature omitted ]
Message 4 in thread
On Apr 25, 2008, at 6:46 PM, Eric Laffoon wrote:
> Hi all,
> maybe this is a novice question, but it's got me scratching my head.
> I want to
> store and retrieve a small list of values and I thought QStringList
> would be
> good. So I declared the variable in the class header...
> QStringList somevar;
> My assumption was that when I inialize it that it would be both
> global and
> persistent so inside one function...
> QStringList somevar;
> somevar.append("one")
> somevar.append("two")
Inside that function if you do this:
QStringList somevar;
you've created a new local variable named "somevar". This isn't
probably what you want. You want to use the somevar you have defined
in your class. In this case, you don't need this line. Just do:
somevar.append("one")
anywhere in your class. Then you'll be using the class member variable.
>
> and inside another function of the same class I want to extract that
> list...
> return somevar.join("\n")
>
> Should that work? Not only do I not see any output, but I
> experimented with
> every variation I could think of with no success. I can't seem to
> find any
> documention and virtually every example I've seen is entirely local
> from
> declaration to output inside a function. It seems like if you can
> decalare it
> outside the function and use it inside without errors it should be
> working,
> right?
>
> --
> Eric Laffoon
> Project Lead Quanta plus/Kommander
> http://kdewebdev.org
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx
> with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
--
[ signature omitted ]
Message 5 in thread
On Friday 25 April 2008 3:58:39 pm Caleb Tennis wrote:
> Inside that function if you do this:
>
> QStringList somevar;
>
> you've created a new local variable named "somevar". This isn't
> probably what you want. You want to use the somevar you have defined
> in your class. In this case, you don't need this line. Just do:
>
> somevar.append("one")
>
> anywhere in your class. Then you'll be using the class member variable.
Hi Caleb,
nice to see you. Funny, but I started out doing it the right way, and when
going back to it didn't work I looked again and realized I had what I thought
was a working conditional statement around my input to test for valid
inforation... nothing in nothing out. At least knowing I should be getting
something out helped. Thanks.
--
[ signature omitted ]