QDomElement.setAttribute crashes program - c++

It's confusing. My program was working reliably. Then, I did some changes in a hurry, they didn't work, re-winded them, went to show my program and it no longer works. My fault for not making new copy every 10min. The thing is however, the program crashes in a place which makes no sense.
QDomElement Expense::toNode()
{
QDomElement e=Entry::toNode(); //Entry is parent of Expense
QString temp;
//std::string getThis=e.nodeName().toStdString();
temp=QString::fromStdString(Category); //Category is string field
//e.hasAttribute("category"); //this works
//e.setAttribute("ha","hi"); //this crashes program
//e.setAttribute("category",temp); //this also crashes program
return e;
}
I thought that maybe in hurry I modified some library, but if I create a new QDomElement, and edit it's attributes, there is no problem at all. Then I thought that maybe my node is not a node at all, but I can use many other functions (like for example e.hasAttribute). Is there limit to amount of attributes we can set? What might be the error?
In case it helps:
QDomElement Entry::toNode()
{
QDomDocument d("EzXpns");
QDomElement e=d.createElement("entry");
QString temp;
temp=QString::fromStdString(Name);
e.setAttribute("name",temp);
temp=QString::fromStdString(to_string(static_cast<long double>(Amount)));
e.setAttribute("amount",temp);
temp=QString::fromStdString(to_string(static_cast<long long>(Date[0])));
e.setAttribute("dateyear",temp);
temp=QString::fromStdString(to_string(static_cast<long long>(Date[1])));
e.setAttribute("datemonth",temp);
temp=QString::fromStdString(to_string(static_cast<long long>(Date[2])));
e.setAttribute("dateday",temp);
temp=QString::fromStdString(Comment);
e.setAttribute("comment",temp);
return e;
}
Edit: I should have specified, that if I try to debug this is the message I get:
TestBuild.exe has triggered a breakpoint
then
Unhandled exception at 0x77d415de in TestBuild.exe: 0xC0000005: Access violation reading location 0x13fb8ff8.
then
0x77d3016e in TestBuild.exe: 0x00000000: The operation completed successfully.
Edit2: Sample xml
<!DOCTYPE data>
<EzXpns>
<account>
<login name="b" password="1"/>
<expHis>
<entry comment="9" dateday="1" name="k" dateyear="0" amount="9" datemonth="1"/>
<entry comment="9" dateday="1" name="b" dateyear="0" amount="9" datemonth="1"/>
<entry comment="9" dateday="1" name="b" dateyear="0" amount="9" datemonth="1"/>
<entry comment="9" dateday="1" name="b" dateyear="0" amount="9" datemonth="1"/>
<entry comment="9" dateday="1" name="b" dateyear="0" amount="9" datemonth="1"/>
</expHis>
<incomeHis/>
</account>
</EzXpns>

Solution was within the Qt documentation.
Look at how I create new element, I do it by calling QDomDocument d("EzXpns"); , which is a mistake. In Qt, after the QDomDocument is destroyed SO ARE ALL CHILD NODES. It worked before just because of pure luck. Creating one QDomDocument, and then passing it around, solved my problem.

Related

rapidxml weird parsing for one specific node

I've been looking for hours a solution to my (simple ?) problem but I cannot find anyone who encountered this. I'm using latest version of rapidxml(1.13).
I'm currently trying to create a tile-based engine and I need to read tmx file.
I'm been using rapidxml for a while and so far everything was great. It was able to read every node perfectly and with an expected behavior. But I came across one node it has a problem with.
This is my tmx file :
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.5" tiledversion="1.6.0" orientation="orthogonal" renderorder="right-down" width="100" height="100" tilewidth="32" tileheight="32" infinite="0" nextlayerid="12" nextobjectid="1">
<tileset firstgid="1" source="../../../Tile_engine/Tile_engine/sprite/[Base]BaseChip_pipo.tsx"/>
<tileset firstgid="1065" source="../../../Tile_engine/Tile_engine/sprite/collision.tsx"/>
<layer id="4" name="background" width="100" height="100">
<properties>
<property name="bg" type="bool" value="false"/>
</properties>
<data encoding="csv">
//I've removed the data for clearer view
</data>
</layer>
<layer id="6" name="object" width="100" height="100">
<properties>
<property name="isSolid" type="bool" value="true"/>
</properties>
<data encoding="csv">
//I've removed the data for clearer view
</data>
</layer>
<layer id="9" name="front" width="100" height="100">
<properties>
<property name="isSolid" type="bool" value="false"/>
</properties>
<data encoding="csv">
//I've removed the data for clearer view
</data>
</layer>
<layer id="11" name="collision" width="100" height="100">
<data encoding="csv">
//I've removed the data for clearer view
</data>
</layer>
</map>
In order to debug, I'm using a basic read with rapidxml :
xml_document<> doc;
xml_node<> * root_node;
// Read the xml file into a vector
ifstream theFile ("sprites/map_wtf.tmx");
vector<char> buffer((istreambuf_iterator<char>(theFile)), istreambuf_iterator<char>());
buffer.push_back('\0');
// Parse the buffer using the xml file parsing library into doc
doc.parse<0>(&buffer[0]);
// Find our root node
root_node = doc.first_node("map");
When I try to read (and count) the layer node for example :
int count_node(0);
for(xml_node<> * child = root_node->first_node("layer"); child != nullptr; child = child->next_sibling())
count_node++;
cout << count_node;
The output is correct and gives me 4.
But when I try to read the tileset node, the output gives me 6.
So I've assumed the behavior is link to the /> at the end of the tileset node (<tileset firstgid="1" source="../../../Tile_engine/Tile_engine/sprite/[Base]BaseChip_pipo.tsx"/>).
Since the nested property node has the same pattern (<property name="bg" type="bool" value="false"/>), I've tried this code :
int count_node(0);
for(xml_node<> * child = root_node->first_node("layer")->first_node("properties")->first_node("property"); child != nullptr; child = child->next_sibling())
count_node++;
cout << count_node;
who gives me the correct output aka : 1.
I've tried different parsing options for the line doc.parse<0>(&buffer[0]) but nothing works. I've also read the content of the buffer during theses tests and it was correct.
I must have the wrong way to read the file but I cannot understand why this script reads layer node and property node fine, but not the tileset ones.
Can anyone help me ?
Thanks !
The question is based on a misunderstanding about the result of
xml_node<> * child = root_node->first_node("layer");
child = child->next_sibling();
The child = child->next_sibling() returns the next node on the same level irregardless of the node name or any other constraint that was applied during the root_node->first_node("layer") selection.
However, the next_sibling signature is basically the same as the first_node signature, so it can be used to apply criteria to the next sibling node to be found.
So the (untested) approach would be like
int count_node(0);
for(xml_node<> * child = root_node->first_node("tileset"); child != nullptr; child = child->next_sibling("tileset"))
count_node++;
cout << count_node;

TinyXML2 doesn't seem to load my file correctly?

I am just starting to use TinyXML2 so I am probably doing something wrong. Anyway:
tinyxml2::XMLDocument txDoc;
tinyxml2::XMLElement *rootnode;
XMLError err = txDoc.LoadFile(xmlFile.c_str()); // err says no error.
rootnode = txDoc.FirstChildElement("common");
rootnode is still set to a null pointer after the final line. I assume this is because it cannot find "common".
Here is my XML (shortened):
<?xml version="1.0"?>
<font>
<info outline="0" spacing="1,1" padding="0,0,0,0" aa="1" smooth="1" stretchH="100" unicode="1" charset="" italic="0" bold="0" size="16" face="Arial"/>
<common blueChnl="0" greenChnl="0" redChnl="0" alphaChnl="1" packed="0" pages="1" scaleH="128" scaleW="256" base="13" lineHeight="16"/>
<pages>
<page file="Font_Arial_16_0.png" id="0"/>
</pages>
<chars count="191">
... (removed additional <char>'s)
<char id="32" chnl="15" page="0" xadvance="4" yoffset="0" xoffset="0" height="16" width="1" y="85" x="121"/>
... (removed additional <char>'s)
</chars>
<kernings count="70">
... (removed additional <kerning>'s)
<kerning amount="-1" second="65" first="32"/>
... (removed additional <kerning>'s)
</kernings>
</font>
However, in the XMLDocument txDoc, the charBuffer only contains:
<?xml version="1.0"?>
<font
And apparently nothing more. So I assume it says there is no error because it finds and opens the file, but doesn't seem to get everything that's inside it.
Does anyone have any ideas? I am using TinyXML2, not 1.
I get the impression I am navigating the file incorrectly.
For the XMLDocument, FirstChildElement() is equivalent to RootElement() and your root element here is font. You want to call FirstChildElement() of the root element.

Does UAA require the login-server to have scope uaa.user?

I've got a deployment where I'm running the UAA sample apps, along with the Java login-server. I've configured my UAA and login-server with a custom uaa.yml and login.yml, respectively. I've populated the uaa.yml based upon the details for the "login" client by looking at the contents of /uaa/uaa/src/main/webapp/WEB-INF/spring/oauth-clients.xml, as shown below:
<entry key="login">
<map>
<entry key="id" value="login" />
<entry key="secret" value="loginsecret" />
<entry key="scope" value="openid,uaa.user" />
<entry key="authorized-grant-types" value="client_credentials,authorization_code" />
<entry key="authorities" value="oauth.login" />
<entry key="autoapprove" value="true" />
</map>
</entry>
Configured this accordingly in my uaa.yml. This seemed to work fine, and I can log in and surf the sample app.
However, when I subsequently visited the /approvals page in the sample app, I got a javascript error in approvals.jsp which was apparently caused by the absence of any corresponding entry for scope.uaa.user in the messages.properties file.
[2013-03-20 18:05:52.787] login/login-server - ???? [http-8080-1] .... DEBUG --- DispatcherServlet: Could not complete request
org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspTagException: No message found under code 'scope.uaa.user' for locale 'en_US'.
at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:491)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:401)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:262)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1180)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:950)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
...
So, the question is -- is scope "uaa.user" really required by the login-server? And, if so, what should the entry in the messages.properties file say? I couldn't find any place that provided the agreed upon text description for uaa.user scope.
As a workaround, I've simply made up my own text for that scope in messages.properties, and the approvals page now renders OK.
Thanks,
John
Yes, the "uaa.user" is required by the login server. You can have any text string in the messages.properties file, which you will use in your application accordingly.
Let me know if that helps.
Thanks,
Hitesh
The login server can't predict what scopes are going to be available, as some may be custom to the application. The bug has been fixed here
https://github.com/cloudfoundry/login-server/commit/c39aa19db33c12a0d9740e2c0a53698b87889ebc
If no message is available to represent the scope, simply print out the name of the scope.

what is coldspring <map> & <list> eqv in wirebox?

I'm porting my Coldspring xml into Wirebox, but I'm stuck.
<map> in Coldspring can create a struct of singletons and then pass that struct into the 'bean' by constructor or setter. And <list> creates an array.
What do I write in Wirebox.cfc to do the same thing?
<bean id="Foo" class="com.foo">
<constructor-arg name="something">
<map>
<entry key="apple">
<ref bean="apple"/>
</entry>
<entry key="banana">
<ref bean="banana"/>
</entry>
</map>
</constructor-arg>
</bean>
<bean id="bar" class="com.bar">
<constructor-arg name="anArray">
<list>
<bean class="com.XX"/>
<bean class="com.YY"/>
</list>
</constructor-arg>
</bean>
Update: I have found a clean way to support this after reading how ColdSpring does it.
First, create a cfc with 2 methods:
component
{
struct function buildStruct() {
return arguments;
}
array function buildArray() {
var array = [];
for (var index = 1; index <= arrayLen(arguments); index++)
array[index] = arguments[index];
return array;
}
}
Then in wirebox config.cfc:
map("Factory")
.to("com.util.wirebox.Factory")
.asSingleton()
.noAutowire();
map("something")
.toFactoryMethod(factory="Factory", method="buildStruct")
.methodArg(name="apple", ref="apple")
.methodArg(name="banana", ref="banana");
map("Foo").to("com.Foo").initArg(name="something", ref="something").asSingleton();
Original Answer:
Luis Majano's Answer:
// Map Binder so you can do utility methods
map("myBinder").toValue( this );
// Map the singleton maps
map("s1Map").toFactoryMethod("myBinder", "buildMap")
.methodArg(name="mapType", value="1");
// Map A service with a singleton map
map("Service").to("path")
.initArg(name="myMap", ref="s1Map");
He suggested me to file an ER, and here is it: http://coldbox.assembla.com/spaces/coldbox/support/tickets/1387-support-for--list--and--map--of-coldspring-xml
Let's break this down and see whats going on here.
1.) You are creating a new bean with an id of foo and its mapped to com.foo. To do this in wirebox use the map method and pass in whatever key you want to reference it by later. Next use the to method to map that key to a path
2.) You want to pass a map (structure) to the components init method. To do so just pass in a normal structure. This can be any value including other beans by using the initWith method.
<cfscript>
map("Foo")
.to("com.foo")
.initWith({apple=apple,banana=banana})
</cfscript>
You can also download the Coldbox plugin for ColdFusion builder. This has a nice little utility in that will allow you to right click on a coldspring definition file and convert it to wirebox. Hope this helps.

error at tinyxml when deserialize

I have the following xml:
<Name />
<Sur> mmm </Sur>
When I deserialize I wrote:
TiXmlElement* section;
section=handle.FirstChild("Name").ToElement()
if (section) {}
The problem is that the if condition is runned though field Name is null. WHY? Where am I wrong?
Appreciate. THX
Maybe you should define a root element of your XML code, like <Person>:
<Person>
<Name />
<Sur> mmm <Sur />
</Person>