Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8385491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:41:07+00:00 2026-06-09T17:41:07+00:00

i have a strange problem with QList and the boost:shared_ptr. I’m afraid i am

  • 0

i have a strange problem with QList and the boost:shared_ptr. I’m afraid i am not able to strip the problem apart, that’s why i will post the wholoe function later on.

What i want to do: I have a list (_fileList) which stores boost::shared ptrs to QFile Objects. The files are XML files. Than i want to parse this file and resolve all includes which means adding the files specified by the include tag also to the _fileList and scanning them for further include tags. The code works fine when resolving 3 includes (in my small test there is only one include per file). The third time the line
boost::shared_ptr file(*iter); leads to a segmentation fault.
I would be glad if anyone of you can help me or give me hints how i can find this bug.

void XmlParser::expandIncludes()
{
//search all files already in the file list for include tags, if any new are found append this file to the file list
    QList<boost::shared_ptr<QFile> >::iterator iter = this->_fileList.begin();
    while(iter!= this->_fileList.end())
    {
        boost::shared_ptr<QFile> file(*iter);
        QDomDocument doc("activeFile");
        if (!file->open(QIODevice::ReadOnly)){
            return;
        }
        if (!doc.setContent(&(*file))) {
            file->close();
            return;
        }
        file->close();
        QDomElement docElem = doc.documentElement();

        QDomNode n = docElem.firstChildElement("include");
        while(!n.isNull()) {
            QDomElement e = n.toElement(); // try to convert the node to an element.
            if(!e.isNull()) {
               QString nextFile = e.text();
               QString nextFileAbsolutePath = this->_workingDir.absolutePath() +"/"+nextFile;
               boost::shared_ptr<QFile> newFileObject(new QFile(nextFileAbsolutePath));
               this->_fileList.append(newFileObject);

            }
            n = n.nextSiblingElement("include");
        }
        doc.clear();
        iter++;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T17:41:08+00:00Added an answer on June 9, 2026 at 5:41 pm

    Iterators pointing to elements in a QList becomes invalid after you insert new elements into the list. You could use a QLinkList instead.

    From the Qt Container docs:

    Iterators pointing to an item in a QLinkedList remain valid as long as the item exists, whereas iterators to a QList can become invalid after any insertion or removal.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a strange problem getting the color of the point that was touched.
I have a strange problem where a XAML control is not visible in the
I have a strange problem: I have a CSV file that I read correctly
I have a strange problem that I've never encountered before, I have data in
I have a strange problem that I can't get my head around: I have
Have a strange problem in that I have a Rake task that seems to
I have a strange problem with mod_rewrite, the rules that are relevant here are:
I have a strange problem in my project. I have a class that inherits
I have some strange problem with PIL not resizing the image. from PIL import
I have a strange problem that's happening with my WCF REST service. For an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.