Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Posts: 47
Registered: ‎01-15-2013
My Device: Z10
My Carrier: N/A

QXmlSimpleReader crash on parse

#include <QXmlSimpleReader>
#include <QXmlReader>
#include <QtXml>
#include <QFile>
#include <QXmlInputSource>
#include <QXmlContentHandler>
#include <QXmlErrorHandler>


QFile inputFile("assets/res/sample.xml"); 
QXmlSimpleReader xmlReader;
QXmlInputSource *source = new QXmlInputSource(&inputFile);
QXmlContentHandler *cHandler;
QXmlErrorHandler *eHandler;
bool ok = xmlReader.parse(source);
if (!ok) fprintf(stderr, "Parsing failed.");

I have tried running through the debugger and get up until the line that starts with bool ok...at which point app simply crashes.  Disassembly below.


00000000:   Failed to execute MI command:
          -data-disassemble -s 0 -e 104 -- 1
          Error message from debugger back end:
          Cannot access memory at address 0x0



Any ideas?  Thanks

Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: QXmlSimpleReader crash on parse



The file should be opened for reading:

if (inputFile.open(QFile::ReadOnly | QFile::Text)) {
  ...parse the file...

But this isn't the only problem:


You are creating two local unitialized variables (cHandler & eHandler) and passing them to xmlReader. Variables are instantiated using operator new, but QXmlContentHandler & QXmlErrorHandler are abstract classes. This means they define which methods must be implemented, but they don't implement these methods or implement only some of them. So these classes shouldn't be directly instantiated at all.


Inherit from these classes and implement their abstract methods in your class. Then set the class implementing the methods as contentHandler & errorHandler for xmlReader.


I hope my explanation wasn't too confusing. Smiley Happy


It might be easier to find a working example and use it as a base.


Andrey Fidrya, @zmeyc on twitter