How to get a line number when parsing with QXmlDefaultHandler? - qt

I am parsing a xml file with QXmlDefaultHandler like this:
void Parser::ParseFilename(const char* pFilename)
{
LOG_DEBUG("Parser::ParseFilename(%s)", pFilename);
ClearState();
m_inputFile.setFileName(pFilename);
QXmlInputSource source( &m_inputFile );
QXmlSimpleReader reader;
reader.setContentHandler( this );
reader.parse( source );
}
I need to know line numbers for error messages. How can I get them?

Use the exception that is passed to QXmlErrorHandler::error() function. You can set a custom error handler using QXmlReader::setErrorHandler().

Answering myself.
I was not completely clear in my question because I didn't write that I need to generate my own custom error messages. For example I need to make complicate validations of certain attributes. Then, if the attribute is invalid, I need to write message like: "Error on line 15454 column 48, attritubute 'number' should be a prime number but is 65536'.
The approach suggested by Ariya Hidayat works only for messages generated by the SAX parser itself (like malformed XML).
For custom messages I need to overload setDocumentLocator ( QXmlLocator * locator ) which tells me about the current locator, and save somewhere the value of the locator like savedLocator = locator; Actual line number is obtained by locator->lineNumber().

Related

Error during compiling: `identifier not found` (code C3861)

I have a field in my acore_characters table named 'rank' with a tinyint which ranges from 0 to 3 inclusive, based on player's progression. I need to read that value at both login and at certain specific circumstances.
I wrote the following PreparedStatement: "SELECT rank FROM acore_characters WHERE guid = ?" and then the code which is supposed to read that value:
uint16 GetCharactersRank(uint64 guid) {
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(mystatement);
stmt->setUInt32(0, GetGUID());
PreparedQueryResult result = CharacterDatabase.Query(stmt);
if (result) {
[...truncated]
and then fetching the result and so on, but then I get a code C8361 when compiling because 'GetGUID':identifier not found in Player.cpp file...what goes wrong? The other GetGUID calls throughout the file dont give this result. I'm not very fond of c++, any help is very appreciated.
It's not recommended to directly patch the core to add customisations to it. Instead, use modules.
An example can be found here: Is it possible to turn a core patch into a module for AzerothCore?
You can have a look and copy the skeleton-module and start modifying it to create your own.
In your case, you probably want to use the OnLogin player hook.

Error Handling in QPrinter

When printing to PDF with QTextDocument and QPrinter is there any way of detecting errors (e.g. not being able to write to the PDF file)?
I'm using the following code:
QTextDocument document;
QPrinter printer( QPrinter::HighResolution );
printer.setOutputFormat( QPrinter::PdfFormat );
printer.setOutputFileName( filename );
document.print( &printer );
In the docs you'll find QPrinter::printerState. So you can definitely do:
if (printer.printerState() == QPrinter::Error)
// do some error handling
I admit that's not a lot work with, as there are only 4 QPrinter::PrinterState's. You might want to do your best to avoid errors in the first place. The detailed description in the doc states:
Note that setting parameters like paper size and resolution on an invalid printer is undefined. You can use QPrinter::isValid() to verify this before changing any parameters.
Additionaly, you could check if the filename you are setting already exists using QFile::exists.
Also, when setting it all up you can call and handle QPrinter::supportedResolutions(), QPrinter::supportedPaperSources() and QPrinter::supportsMultipleCopies(). Of course, printing to PDF you might not have to worry about these.
It seems like printerState does return an error when failing to write a file as long as the file name is valid. If the file name is not valid it returns idle.

Trying to figure out what this line of code means

This code is from a program I use to enter and track information. Numbers are entered as work orders (WO) to track clients. But one of the tables is duplicating the WO information. So I was trying to figure out a general outline of what this code is saying so that the problem can be fixed.
Here is the original line:
wc.dll?x3~emproc~datarecord~&ACTION=DISPLAY&TABLE+WORK&KEYVALUE=<%work.wo%&KEYFIELD=WO
What I think I understand of it so far, and I could be very wrong, is:
wc.dll?x3~emproc~datarecord~&ACTION
//No clue because don't know ~ means or using & (connects?Action)
=DISPLAY&TABLE+WORK&KEYVALUE
//Display of contents(what makes it pretty) and the value inside the table at that slot
=<work.wo%&KEYFIELD
//Calling the work from the WO object
=WO
//is Assigning whatever was placed into the WO field into the left side of the statement
I'll do my best to interpret the statement, with the limited information you've provided:
wc.dll is an instruction to invoke a DLL
? is introducing a list of parameters (like a query string in HTTP)
x3~emproc~datarecord~ seems like a reference to a function in the dll
& parameter separator
ACTION=DISPLAY set the ACTION parameter to the value DISPLAY
TABLE+WORK perhaps sets a couple of flags
KEYVALUE=<%work.wo% set the KEYVALUE parameter to the value of <%work.wo%
KEYFIELD=WO set the KEYFIELD parameter to the value WO
Hope that helps.

Retrieve explicit values from document library

I'm trying to pull some fields from my Document Library. Right now, I can retrieve these 2 fields to return the correct values, in my success function.
while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
alert(oListItem.get_item('Title'));
alert(oListItem.get_item('UserField1'));
}
But when I try to call a computed field, such as 'NameOrTitle' oListItem.get_item('NameOrTitle')); I get IE telling me the property or field has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.
This value has content inside it right now. And I need it, as it's displaying the file name. How can I get this field? I have looked elsewhere and I have read stuff about doing:
context.load(allItems, 'Include(NameOrTitle)');
Then in my succeess function, I do oListItem.get_nameOrTitle(). Is this correct?
Well I do that and now I'm getting
Object doesn't support property or method 'get_nameOrTitle'
Please help. Thanks.
oListItem.get_item('FileRef');
Will get me the url

filter functions problem

I'm working on a search component for an app I'm working on and I needed to add some filters to it. I've found an example and got the first filter working fine.
Now I'm trying to add a second filter I'm running into problems... In the example I found they use filterFunctions, but I only get an option for filterFunction, why is that?
Here's the example code
productsCollection.filterFunctions =
[
filterByPrice, filterByType,
filterByCondition, filterByVendor
]
And this is what I'm trying
acData.filterFunction = [filterByStatus, filterByDate]
but with this code I get the following error message - 1067: Implicit coercion of a value of type Array to an unrelated type Function.
Why am I getting this error and how would I go about add multiple filters to my Array Collection?
Thanks!
filterFunction must be set to a single function, not an Array or any other datatype. To combine multiple functions create one that combines them, like this:
acData.filterFunction = function(item:Object)
{
return
filterByPrice(item) &&
filterByType(item) &&
filterByCondition(item) &&
filterByVendor(item);
};
If you saw a sample that used filterFunctions plural that accepted an array, post a link. That's not anywhere in the standard Flex framework or in the new 4.0 beta afaik.
It looks like you are going to have to extend an arraycollection to make it work. this link should spell it out for you: http://blog.rotundu.eu/flex/arraycollection-with-multiple-filter-functions/

Resources