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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:07:16+00:00 2026-05-18T05:07:16+00:00

I am having some issues with a segmentation fault being caused by access to

  • 0

I am having some issues with a segmentation fault being caused by access
to a member variable in a Qt application. My experience of segmentation
faults have shown them generally to be a result of accessing a memory
location that is out of bounds. However, I’m struggling to figure out
why this would be the case in my code.

The class in question is a subclass of QFrame and contains a number of
member variables, including one originally called m_Zoom of type
unsigned int. When the frame is created, a number of functions are called
that cause the zoom level to be set and then the window is drawn. This
all works fine. There are then a number of ways that the zoom level can
be changed: opening a new file or pressing either + or -. These read
the existing zoom level and then decide whether to change it. Simply
reading the existing zoom level causes a segmentation fault.

Note that this variable is not a pointer or in an array or anything
unusual. The definition was along the lines of:

class MyClass : public QFrame
{
    Q_OBJECT

public:
    MyClass(QWidget *parent = 0);
    void SetZoomLevel(unsigned int zoom);
    void ZoomIn();

protected:
    void mousePressEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
    void paintEvent(QPaintEvent *event);

private:
    // A number of private functions for performing calculations

    // Some variables including:
    double m_OriginShift;
    unsigned int m_Zoom;
    // Some more variables
};

The function paintEvent and all the mouse* event functions access
m_Zoom and these work fine (the mouse is used to move the view
around). The constructor calls SetZoomLevel (which is basically
m_Zoom = zoom). Again, this works with no problems. ZoomIn starts
with:

void MyClass::ZoomIn()
{
    qDebug() << "Zoom In";
    unsigned int existingZoom = m_Zoom; // [1]
    qDebug() << "Existing zoom is " << existingZoom;

    ...

The segmentation fault happens in this function, before the second
qDebug reports anything.

I’ve tried stepping through the application in cygwin’s gdb and I get to
the line marked [1] and type stepi and get an immediate segfault.

Having moved the variable around (in case something else was overwriting
it’s location), changed to using a pointer with mallocd memory, moved
it into a separate structure, moved it into a separate class (both with a member instance and with a member pointer with a new line in the constructor) and
probably a few other random and unsuccessful acts of desperation, I’ve
completely run out of ideas.

Please can anyone suggest any good ways that I could go about debugging
this issue?

I’m using Qt 4.6.3 on Windows XP compiling with GNU Make 3.81 and g++
version 4.4.0 (from the mingw that came with the Qt installer).

  • 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-05-18T05:07:17+00:00Added an answer on May 18, 2026 at 5:07 am

    While this is a wild guess, there’s a possibility that you’re calling that method on a null object.

    Note that:

    unsigned int existingZoom = m_Zoom;
    

    is equivalent to

    unsigned int existingZoom = this->m_Zoom;
    

    If you called this method from a null pointer:

    someUninitializedPtr->ZoomIn();
    

    then this is probably the result you’d get – a segmentation fault upon first try of dereferencing this pointer, having the value of null.

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

Sidebar

Related Questions

I have been having some issues with LINQ-To-SQL around memory usage. I'm using it
Having some issues running my code local. I have host file setup like this:
Having some issues with C. I have this is my code: // First line
Having some issues getting this MPMoviePlayerViewController to work. I have two sample URLs pointing
We've been having some issues with a SharePoint instance in a test environment. Thankfully
I'm having some issues with producing an int matrix without creating memory leaks. I
We are having some issues getting SharePoint to work as we want it to.
I am having some issues with using the OrderBy extension method on a LINQ
I am using Fluent NHibernate and having some issues getting a many to many
I'm having some inheritance issues as I've got a group of inter-related abstract classes

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.