Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to read QString and bool values from xml ?
QtWS25 Last Chance

How to read QString and bool values from xml ?

Scheduled Pinned Locked Moved General and Desktop
xmlstruct
5 Posts 2 Posters 9.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Ratzz
    wrote on 24 Jul 2015, 05:44 last edited by
    #1

    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?

    --Alles ist gut.

    J 1 Reply Last reply 24 Jul 2015, 11:16
    0
    • J Offline
      J Offline
      JohanSolo
      wrote on 24 Jul 2015, 06:22 last edited by
      #2

      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.

      `They did not know it was impossible, so they did it.'
      -- Mark Twain

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Ratzz
        wrote on 24 Jul 2015, 06:35 last edited by Ratzz
        #3

        @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

        --Alles ist gut.

        1 Reply Last reply
        0
        • R Ratzz
          24 Jul 2015, 05:44

          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?

          J Offline
          J Offline
          JohanSolo
          wrote on 24 Jul 2015, 11:16 last edited by JohanSolo
          #4

          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.

          `They did not know it was impossible, so they did it.'
          -- Mark Twain

          1 Reply Last reply
          1
          • R Offline
            R Offline
            Ratzz
            wrote on 24 Jul 2015, 13:32 last edited by
            #5

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

            --Alles ist gut.

            1 Reply Last reply
            0

            5/5

            24 Jul 2015, 13:32

            • Login

            • Login or register to search.
            5 out of 5
            • First post
              5/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved