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 8535811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:31:16+00:00 2026-06-11T10:31:16+00:00

I am working on my first Qt application, widget really, and I am getting

  • 0

I am working on my first Qt application, widget really, and I am getting a segfault when I try to fill up a standard library map with a <int, QString> pair. My goal is to fill the map with int keys and QString values. I don’t know if pair is the best way to do this, so any advice would be great.

Here is the only source file besides the main.

#include "linuxtips.h"
#include "ui_linuxtips.h"

LinuxTips::LinuxTips(QWidget *parent) :
  QWidget(parent),
  ui(new Ui::LinuxTips)
{
  loadRandTip();
  ui->setupUi(this);
}

LinuxTips::~LinuxTips()
{
  delete ui;
}

void LinuxTips::on_learnMore_clicked()
{

}

void LinuxTips::on_viewAll_clicked()
{

}

void LinuxTips::loadRandTip()
{
  int i = 0;
  std::map<int, QString>::iterator it;

  QString line;
  QFile inputFile(":/tipFile.txt");
  inputFile.open(QIODevice::ReadOnly);

  QTextStream in(&inputFile);
  do{
    line = in.readLine();
  //  this->TipMap.insert(it, std::pair<int, QString >(i,line));
    i++;
  }while(!in.atEnd());
}

If I uncomment this->TipMap.insert(it, std::pair<int, QString >(i,line)); then it will run. Since it’s a seg fault I’m sure its a memory overflow or null pointer, but I’m just not sure what it is. Thanks for any help.

  • 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-11T10:31:18+00:00Added an answer on June 11, 2026 at 10:31 am

    I’m going to assume that your crash is due to these lines:

    std::map<int, QString>::iterator it;
    this->TipMap.insert(it, std::pair<int, QString >(i,line));
    

    You’re attempting to insert into a map using an invalid (uninitialized) iterator. Are you running this in debug or release? You should get an assertion in debug.

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

Sidebar

Related Questions

I am new to wpf and i am working on first application i have
Am working with my first storyboard application and am having a problem. When I
I am working on my first Grails application, which involves porting over an old
I've been working on my first Metro application and I'm wanting to change my
I'm currently working on my first MVC3 application at work (using the Razor view
I've been working on writing my first MVC3 application for a little while and
I am working on a MVC3 code first web application and after I showed
I am working on a fairly basic screen layout for my first Android application
I'm working on my first very complex JQuery based application. A single web page
I'm currently working on my first deployment of a large server side application which

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.