QXmlQuery 没有结果
我对此感到非常沮丧...
使用这个简单的 xml:
<?xml version='1.0'?>
<root>
<data>hello</data>
</root>
这段代码
QXmlQuery xquery;
xquery.setQuery( "doc('config.xml')//data" );
if( xquery.isValid() )
{
QXmlResultItems itemResult;
xquery.evaluateTo( &itemResult );
QXmlItem item( itemResult.next() );
while( !item.isNull() )
{
QVariant value = item.toAtomicValue();
qDebug() << "One XML result!!!";
item = itemResult.next();
}
}
这段代码根本不会给我任何结果。 我检查了应用程序的执行路径与config.xml所在的位置相同。
官方文档对我帮助不大,而且互联网上似乎没有关于如何使用此类的详细信息的额外信息。
我有另一个程序可以成功从 xml 加载数据,并且代码与发布的代码完全相同。如果找不到 xml 文件,甚至会抛出错误(我当前的应用程序不会发生这种情况)。
当然,我正在配置 .pro 文件以使用 xmlpatterns:
QT += xmlpatterns
有任何线索吗?
I'm getting really fustrated with this...
With this simple xml:
<?xml version='1.0'?>
<root>
<data>hello</data>
</root>
And this code
QXmlQuery xquery;
xquery.setQuery( "doc('config.xml')//data" );
if( xquery.isValid() )
{
QXmlResultItems itemResult;
xquery.evaluateTo( &itemResult );
QXmlItem item( itemResult.next() );
while( !item.isNull() )
{
QVariant value = item.toAtomicValue();
qDebug() << "One XML result!!!";
item = itemResult.next();
}
}
This code simply doesn't throw me any results.
I've checked that the execute path of app is the same where the config.xml is located.
Official documentation doesn't help me very much and seems there's no extra info on internet about details on how to use this class.
I have another program that successfully loads data from an xml and the code is exactly like the posted one. Even throws me an error if xml file is not found (a thing that with my current app doesn't happens).
Of course I'm configuring the .pro file to use xmlpatterns:
QT += xmlpatterns
Any clue??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我记得我也遇到了一些麻烦...无论如何,我发现我正在使用以下几行:
我希望它会对您有所帮助!
I remember I had some trouble with it as well... Anyway, I've found that I was using the following lines :
I hope it will help you a bit !