Skip to content
  • 0 Votes
    4 Posts
    596 Views
    VRoninV

    I'm sorry but you must be moving the cursor in some way. Try putting Q_ASSERT(m_node.isStartElement()); just before auto x = m_node.attributes().size();

    This example parses the XSD you provided correctly (I also let QXmlStreamReader handle namespaces instead of having to write custom code for it):

    int main() { const QString xmlText(R"***(<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:element name = "elementName"> <xs:simpleType> <xs:restriction base = "xs:string"> </xs:restriction> </xs:simpleType> </xs:element> </xs:schema>)***" ); QXmlStreamReader reader(xmlText); while (!reader.atEnd()) { switch(reader.readNext()){ case QXmlStreamReader::StartDocument: qDebug("Start of document"); break; case QXmlStreamReader::EndDocument: qDebug("End of document"); break; case QXmlStreamReader::StartElement:{ qDebug() << "Started Element: " << reader.name(); const auto attr = reader.attributes(); qDebug() << "Number of Attributes: " << attr.size() << " Attributes:"; for(auto&& att : attr) qDebug() << att.name() << " = " << att.value(); } break; case QXmlStreamReader::EndElement: qDebug() << "Finished Element: " << reader.name(); break; default: break; } } return 0; }
  • 0 Votes
    2 Posts
    182 Views
    SGaistS

    Hi,

    You will have to use the corresponding private module in your project.

  • 0 Votes
    6 Posts
    359 Views
    mrjjM

    @qt_emp
    Hi
    Yes it will work.
    https://doc.qt.io/archives/qt-4.8/qtglobal.html#qInstallMsgHandler
    (name is slightly different. works the same as far as i know)

  • 0 Votes
    2 Posts
    720 Views
    JonBJ

    @alizadeh91
    I don't have a solution for you, only a warning. If you intend to parse arbitrary C++ files from anywhere, rather than some terribly cut-down subset whose layout you know intimately, you're going to find this very hard to do. Very, very hard!

    Heck, you can't even write a grammar for parsing C++ source files because of the pre-processor, e.g. http://trevorjim.com/c-and-cplusplus-are-not-context-free/

    To parse C and C++, you start by using a very powerful preprocessor. These preprocessors are inevitably written by hand (they are not based on a theoretic foundation like regular expressions or context-free grammars).

    As far as I am aware, there is no open source which will produce a standalone parse tree for you. The consensus (search the web) is that you really need to try to leverage an existing C++ compiler to do such a job. You could look at gcc, or perhaps more likely clang. I still don't think you'll get what you want out of them.

    If all you want to do is some hacky approximation which just extracts #include statements so that you can follow them then you could do something with QRegularExpressions. Correctly locating & extracting the definition of functions in .cpp/.h files will be harder --- you'll probably end up making all sorts of assumptions as to where definitions start & end more on a line-by-line basis than via regular expressions or proper parsing. It may do you for your purposes, provided you are happy with some vague approximation which is not robust.

    Sorry, but good luck!

  • 0 Votes
    3 Posts
    3k Views
    P

    very helpful. Thank you!

  • Parsing JSON in QML

    Solved QML and Qt Quick
    3
    0 Votes
    3 Posts
    2k Views
    Stefan Monov76S

    @Wieland: Thanks!

  • Parse HTML in Qt 5.7

    Unsolved General and Desktop
    12
    0 Votes
    12 Posts
    5k Views
    A

    @Joel-Bodenmann So I can just use "runJavaScript" function ?!

    @SGaist No, that was just an example !! :D

  • 0 Votes
    2 Posts
    1k Views
    OkynO

    I have found a workaround but I am still open with a better idea..

    I have modify this source file of qt creator "src/plugins/qmldesigner/qmldesignerextension/connectioneditor/bindingmodel.cpp"
    I added the field "Global" in "Source Item" and when Global is selected in souce item I read my js file and with a regexp I add variables in "Source Property"

  • 0 Votes
    1 Posts
    1k Views
    No one has replied
  • 0 Votes
    4 Posts
    2k Views
    mrjjM

    @Ralf
    Oh, :(
    Well in that case I would download source code for whole Qt
    and have a look of what they use for
    the qss (css) parsing and see if some could be reused. ( i have no idea)

    Also
    http://www.codeproject.com/Articles/20450/Simple-CSS-Parser

    is a good read (IMO) for toughs about writing such parser.

    Good luck