How to read QString and bool values from xml ?



  • How to read read QString and bool values from xml ?
    This way i cannot convert .

    struct Settg
    {
        ushort DataBlock[32];
        bool Status[32];
    }
    
    Settg get_Settg;
    if(xmlReader->name() == "DATABLOCK")
      {
        get_Settg.DataBlock = xmlReader->readElementText().toUShort();
         xmlReader->readNext();
        }
      else if(xmlReader->name() == "STATUS")
      {
     get_Settg.Status =(xmlReader->readElementText()).toUpper()=="true"?1:0;
     xmlReader->readNext();
     }
    

    Where did i miss ? Did i miss somthing?



  • What is the exact output? What do you mean with "I cannot convert"?

    get_Settg.Status =(xmlReader->readElementText()).toUpper()=="true"?1:0;
    

    This line looks suspicious to me: you're converting the string to UPPERCASE and then comparing with a lowercase "true", then 1 and 0 are no proper boolean values. I would correct this line in

    get_Settg.Status = ( xmlReader->readElementText()).toUpper() == "TRUE" )
    

    As a general note, the type converting method of QString can give you the status of the conversion, this status should be checked to be sure you're not reading garbage information.



  • @JohanSolo
    Thanks for the reply .
    My XML Output looks like this

    -<SETTINGS>
        -<R NUMBER="0">
             <ISENABLED>TRUE</ISENABLED>
            -<SA0>
                  <DATABLOCK>Table 0</DATABLOCK>
                  <STATUS>TRUE</STATUS>
             </SA0>
               .
               .
            -<SA31>
                 <DATABLOCK>Table 0</DATABLOCK>
                  <STATUS>TRUE</STATUS>
            </SA31>
         </R>
    <?SETTINGS>
    

    How to read BLOCKDATA?

    How to read Bool which is an array?

    get_Settg.Status = ( xmlReader->readElementText()).toUpper() == "TRUE";
    
    error: C2440: '=' : cannot convert from 'bool' to 'bool [32]'
    There are no conversions to array types, although there are conversions to references or pointers to arrays


  • You defined the structure as

    struct Settg
    {
        ushort DataBlock[32];
        bool Status[32];
    }
    

    and then you're using it as

     get_Settg.DataBlock = //...
    get_Settg.Status = // ...
    

    You have to provide and index to the array, i.e.

    get_Settg.Status[ theIndex ] = // ...
    

    EDIT: you're facing a C++ issue, not a problem of reading an XML file.



  • @JohanSolo
    Thank you . I used index to read an array.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.