Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. "Avoid unnamed objects ..." warning when using QDomNode::appendChild
Forum Update on Monday, May 27th 2025

"Avoid unnamed objects ..." warning when using QDomNode::appendChild

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 2.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bart_Vandewoestyne
    wrote on 4 Jul 2019, 13:05 last edited by Bart_Vandewoestyne 7 Apr 2019, 13:20
    #1

    Using Qt 5.12.4, quite recently we switched from Visual Studio 2015 to Visual Studio 2019. Using Visual Studio 2019, the lines

    QDomDocument doc;
    const auto fooElement = doc.createElement("Foo");
    doc.appendChild(fooElement);
    

    result in the warning

    C26444 Avoid unnamed objects with custom construction and destruction (es.84).
    

    Looking at the documentation at https://doc.qt.io/qt-5/qdomnode.html#appendChild I see that appendChild returns a new reference to fooElement on success or a null node on failure. Does that mean I could do something like the following to make the warning go away?

    QDomDocument doc;
    auto fooElement = doc.createElement("Foo");
    fooElement = doc.appendChild(fooElement).toElement();
    if (fooElement.isNull()) {
        // handle error case
    }
    // do stuff with fooElement
    

    or am I misunderstanding things here?

    J 1 Reply Last reply 5 Jul 2019, 06:07
    0
    • B Bart_Vandewoestyne
      4 Jul 2019, 13:05

      Using Qt 5.12.4, quite recently we switched from Visual Studio 2015 to Visual Studio 2019. Using Visual Studio 2019, the lines

      QDomDocument doc;
      const auto fooElement = doc.createElement("Foo");
      doc.appendChild(fooElement);
      

      result in the warning

      C26444 Avoid unnamed objects with custom construction and destruction (es.84).
      

      Looking at the documentation at https://doc.qt.io/qt-5/qdomnode.html#appendChild I see that appendChild returns a new reference to fooElement on success or a null node on failure. Does that mean I could do something like the following to make the warning go away?

      QDomDocument doc;
      auto fooElement = doc.createElement("Foo");
      fooElement = doc.appendChild(fooElement).toElement();
      if (fooElement.isNull()) {
          // handle error case
      }
      // do stuff with fooElement
      

      or am I misunderstanding things here?

      J Online
      J Online
      jsulm
      Lifetime Qt Champion
      wrote on 5 Jul 2019, 06:07 last edited by
      #2

      @Bart_Vandewoestyne said in "Avoid unnamed objects ..." warning when using QDomNode::appendChild:

      Does that mean I could do something like the following to make the warning go away?

      Did you try?

      https://docs.microsoft.com/en-us/visualstudio/code-quality/c26444?view=vs-2019

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • B Offline
        B Offline
        Bart_Vandewoestyne
        wrote on 5 Jul 2019, 13:09 last edited by
        #3

        Yes, I did, and the warning goes away. I was just wondering if

        doc.appendChild(fooElement)
        // do stuff with fooElement
        

        was going to do the same as

        fooElement = doc.appendChild(fooElement).toElement();
        // do stuff with fooElement
        

        Using VS2019, I checked the value of fooElement's impl pointer, and the value before and after the call to

        fooElement = doc.appendChild(fooElement).toElement();
        

        was the same. So to be really on the safe side, I would say that

        QDomDocument doc;
        auto fooElement = doc.createElement("Foo");
        fooElement = doc.appendChild(fooElement).toElement();
        if (fooElement.isNull())
        {
            // handle error
        }
        // do stuff with fooElement
        

        is the safest way to append the child. However, I often simply see

        QDomDocument doc;
        const auto fooElement = doc.createElement("Foo");
        doc.appendChild(fooElement);
        

        from which I would think that most often, people simply do not check for appendChild errors.

        Any comments on this? Am I overlooking something? Could C++17's [[maybe_unused]] attribute come in handy here? Feel free to share thoughts.

        1 Reply Last reply
        0

        2/3

        5 Jul 2019, 06:07

        • Login

        • Login or register to search.
        2 out of 3
        • First post
          2/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved