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. QtXmlPatterns using QXmlItem to focus in QXmlQuery cannot get results.
Forum Updated to NodeBB v4.3 + New Features

QtXmlPatterns using QXmlItem to focus in QXmlQuery cannot get results.

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.0k Views 1 Watching
  • 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.
  • N Offline
    N Offline
    Neuxstein
    wrote on last edited by
    #1

    Hi all,

    I try to query a node say the following :"/TestRun/Config/Test/PA/Pulse" with the code bellow:
    @ QFile* file = new QFile("/home/user/hardwaretest.xml");
    qDebug() << file->open(QIODevice::ReadOnly);

    QXmlQuery query;
    
    query.setFocus(file);
    query.setQuery("/TestRun/Config/Test/PA/Pulse");
    
    QXmlResultItems* results = new QXmlResultItems();
    query.evaluateTo(results);
    
    QXmlItem item = results->next();
    
    while(!item.isNull())
    {
        if(item.isNode())
        {
          QXmlQuery query2;
    
          query2.setFocus(item);
           query2.setQuery("./@pulseWidth/string()");
    
          QXmlResultItems* results2 = new QXmlResultItems();
          query2.evaluateTo(&results2);
    
          QXmlItem item2 = results2->next();
    
          while(!item2.isNull())
          {
            if(item2.isAtomicValue())
                qDebug() << item2.toAtomicValue().toString();
            if(item2.isNode())
                qDebug() << "item2 is a node";
            item2 = results2->next();
          }
          delete results2;
        }
      item = results->next();
    }
    
    file->close();
    delete file;
    delete results;@
    

    Here is a part of my xml file :

    @<?xml version="1.0" encoding="UTF-8"?>
    <TestRun>
    <Config>
    <Test name="Pulser">
    <PA>
    <!-- amplitude % - pulseWidth % - riseTime V/ns - reverberation % -->
    <Pulse amplitude="0.1" pulseWidth="0.1" riseTime="10" reverberation="0.04" />
    </PA>
    <UT>
    <!-- amplitude % - pulseWidth % - riseTime V/ns - reverberation % -->
    <Pulse amplitude="0.1" pulseWidth="0.1" riseTime="10" reverberation="0.04" />
    </UT>
    </Test>
    <TestRun>@

    I do get the node
    @<Pulse amplitude="0.1" pulseWidth="0.1" riseTime="10" reverberation="0.04" />@

    on the first query, but the second only return an empty node...

    I never were able to get results with QXmlQuery focused on an QXmlItem.

    Somebody knows what I do wrong here?
    Thank in advance.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dvolosnykh
      wrote on last edited by
      #2

      Figured out how to do such things. One can view the solution "here":http://stackoverflow.com/a/27117841/694123.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dvolosnykh
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0

        • Login

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