Skip to content
QtWS25 Call for Papers
  • 0 Votes
    11 Posts
    835 Views
    B

    @Christian-Ehrlicher said in Dynamic XML documents instead of `.ui` files in Qt:

    @brainchild The uiloader is just a way to load xml files which in 99,9% are processed by uic and compiled directly instead. So adding this complexity to pass a DOM instead a simple QIODevice for the max. 0,1% use case is fine in my pov.
    Esp.since there is no need for a DOM and QtCore don't have a DOM class at all - QXmlStreamReader is perfectly fine for this simple task.

    The XML module has a DOM representation. Why would it not be sensible for a version to be provided of load() that processes a DOM representation from this module?

  • 0 Votes
    2 Posts
    259 Views
    Christian EhrlicherC

    QtXmlPatters was dropped (for good reasons - unmaintainable), For the two others see https://www.qt.io/blog/qt-extras-modules-in-qt-6

  • 0 Votes
    2 Posts
    274 Views
    SGaistS

    Hi and welcome to devnet,

    You should provide a minimal compilable example that shows your issue. That way people will be able to analyse what is happening.

  • 0 Votes
    2 Posts
    324 Views
    JonBJ

    @pavanforza
    Hello and welcome.

    Qt supports SQLite as a database, which is very simple to set up and use (file based). You can still send it SQL queries/statements to execute through the same Qt QSql...classes as would be used against an Oracle database.

  • 0 Votes
    5 Posts
    1k Views
    J

    @jsulm Thank you very much !

    It's exactly what I needed.

    In the top !

  • 0 Votes
    6 Posts
    536 Views
    BeaverShallBurnB

    @sierdzio, false alarm!

    After reopening my project everything got built and no file existance errors were present. Your hint about adding QCoreApplication really helped!

  • 0 Votes
    4 Posts
    636 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
    3 Posts
    471 Views
    VRoninV

    You need to be more specific. xml doesn't have arrays, how should arrays be treated?

  • 0 Votes
    4 Posts
    623 Views
    RipleyR

    @mrjj Hey bro thanks a lot that article was help me a lot to solve it.

  • 1 Votes
    6 Posts
    2k Views
    R

    A colleague asked for me on the mailing list and that was the answer:

    regarding the 'deprecated' state of XmlPatterns: There wont be an further development for this module, but I also doubt that it will be removed before Qt 6. So as long as you're using Qt 5 you're safe to use XmlPatterns. Qt 6 might be still 2 years away, and as you're using it professionally, I assume that you'll probably wait at least till the release of Qt 6.1 (or even longer) anyway before upgrading your project to it. Until then there might be another Qt (conforming) solution to the problem.

    So in my opinion you've got 2 options (depending on the scope and lifecycle of your project):
    a) use the Xml Schema related classes from the XmlPatterns module and worry about it going away (much) later, and maybe even have a Qt (conforming) solution by then, or
    b) use an external library like CodeSynthesis XSD or something similar and worry about their API changes and usage and naming patterns that differ from Qt's patterns etc.

    IMHO using the Qt modules while they are still available is usually the better option.

    [[by Yves Maurischat]]

    I hope that helps other developers with similar questions. I mark this as solved in the sense that there is some sort of answer here, although maybe it's not completely satisfying.

  • General Purpose Data Serializer

    Unsolved Showcase
    7
    6 Votes
    7 Posts
    1k Views
    Joel BodenmannJ

    We've added support for the first Qt types: QString and qreal.
    You can now do this:

    class Color : public Gpds::Serialize { public: QString name; int red; int green; int blue; virtual Gpds::Container toContainer() const override { Gpds::Container c; c.setComment("a color object"); c.addAttribute("format", "rgb"); c.addAttribute("name", name); c.addValue("red", red).addAttribute("depth", "32"); c.addValue("green", green).addAttribute("depth", "32"); c.addValue("blue", blue).addAttribute("depth", "32"); return c; } virtual void fromContainer(const Gpds::Container& c) override { // Retrieve format const QString& formatString = c.getAttribute("format").value_or("n/a"); assert( formatString == "rgb" ); name = c.getAttribute("name").value_or("n/a"); red = c.getValue<int>("red"); green = c.getValue<int>("green"); blue = c.getValue<int>("blue"); } };

    Which will result in the following XML:

    <color format="rgb" name="Black"> <blue depth="32">0</blue> <green depth="32">0</green> <red depth="32">0</red> </color>

    There's also a Qt specific demo/example in the repo.

    Isn't the world wonderful?
    There's still a lot of stuff left to do tho.

  • 0 Votes
    2 Posts
    780 Views
    jsulmJ

    @HW-Developer Start here http://doc.qt.io/qt-5/qtxml-index.html

  • 0 Votes
    2 Posts
    735 Views
    SGaistS

    Hi,

    QDomDocument comes to mind for that kind of thing. There's no easy way to modify a file "in-place".

  • 0 Votes
    6 Posts
    2k Views
    sierdzioS

    @TheTrueGoofy said in Read and write QBrush (QPen, QFont) as XML:

    Certainly this is also quite simple to implement, but I was hoping that there is a more elegant solution.

    I think the only other way is to create feature request for QtGui, or implement a Qt patch yourself - to add a QBrush::toString() method (or QTextStream overload), with a corresponding QBrush::fromString().

  • 0 Votes
    7 Posts
    2k Views
    L

    @koahnig Thanx mate

  • 0 Votes
    12 Posts
    5k Views
    SGaistS

    Again, it wasn't a suggestion, I was just asking whether you would simply do tag for tag replacement.

    Out of curiosity, since you are using doxygen, why not make it generate the html directly ?

  • 0 Votes
    3 Posts
    1k Views
    P

    Hi,
    Creating a very "abstract" xml parser is not easy and it's quite error-prone. You have to know some (or at least one) parent or common tag names in order to have a starting point for any deeper "abstract" parsing. Basically, you have to move the parser step by step checking everything in the way. For example, you could use a simple function as an entry point for the following function when you meet a specific tag:

    void XmlReader::readFragment() { Q_ASSERT(m_reader->isStartElement()); //Make sure the xmlreader is at an opening tag const QString p = m_reader->qualifiedName().toString(); // From now on, you will work with this opening tag //Do what you want, for example handle attributes and their values for (auto i = 0; i < m_reader->attributes().count(); ++i) { ... } m_reader->readNext(); //Move on ... //Do everything manually like this if (m_reader->isCharacters) { ... } else if (m_reader->isEndElement()) { ... } //or like this //Eventually, you have to check for the closing current tag, exit the function, //and return the control to the "entry point" function while (!m_reader->isEndElement() && !m_reader->qualifiedName().toString() == p) { ... //Do your work m_reader->readNext(); } }

    However, with this approach, things can get extremely complicated if there are nested tags, for example:

    <p> <note> <p>...</p> </note> </p>

    Maybe it would be easier to subclass QXmlStreamReader but it would help to provide some sample xml data and more info on what exactly you want to do.

  • 0 Votes
    2 Posts
    668 Views
    matthew.kuiashM

    @Pradeep-Kumar Do you have your code please? Sounds like you're adding nodes at the root level. You need to insert a sibling after the first/second node.