[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] QStringList - hvordan trækker jeg en værdi ud?



Fredag den 6. januar 2006 02:32 skrev Thomas Jansson:
> Hej alle
>
> Jeg har et program Qt program hvor jeg henter en kommasepereret liste ind i
> QstringList objekt og jeg spørg derefter om strørelsen af listen (antallet
> af elementer) med:
>
> QStringList bKoeff(QStringList::split(",",koefficientLineEdit->text()));

Bemærk at split er flyttet til QString i QT 4.

> int bSize = bKoeff.count();

Du bør bruge 
QValueList::size_type bSize

>
> Nu ville jeg rigtigt gerne hente en værdi ud af listen og har prøvet
> følgende:
>
> double iValue = bKoeff[bSize-1];

QStringList::operator[] returnerer en QString, som du ikke kan autotypecaste 
til en double ;-)

Du kan skrive 
bool OK;
double iValue = bKoeff[bSize-1].toDouble( & OK );
if ( ! OK ) {
	throw "Error in converting... blablab";
} 

se dok for toDouble.

>
> Men så får jeg en fejl når jeg kompiler, der hedder:
>
> .ui/../form1.ui.h:121: error: cannot convert 'QString' to 'double' in
> initialization
>
> Så jeg skal hente værdien ud på en anden måde, men hvordan? Jeg har prøvet
> at kigge på:
> http://doc.trolltech.com/3.3/qstringlist.html og
> http://doc.trolltech.com/3.3/qvaluelist.html
> men jeg kan simpelthen ikke finde en funktion til at hive et element ud af
> listen med?

[] hiver elementet ud. Dit problem er er hive værdien af en bool ud af 
strengen.

Mvh

Mads

-- 
Mads Bondo Dydensborg.                               sslug@sslug
There are many gods which Christians reject. I just believe in one less god
then they do. The reasons that you might give for your atheism toward the
Roman gods are likely the same reasons I would give for not believing in
Jesus.
                               - Dan Barker


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2006-02-01, 02:01 CET [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *