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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:36:21+00:00 2026-06-04T16:36:21+00:00

I am developing a custom exception, where I’d need a QString member. Something like:

  • 0

I am developing a custom exception, where I’d need a QString member. Something like:

class MyException
{
private:
    const QString fDescription;

public:
    MyException(QString desc);
};

MyException::MyException(QString desc) : fDescription(desc)
{}

When I try to use it:

if (isErrorEncountered)
{
    MyException e(QString("Descriptive message here..."));
    throw e;
}

I get a segmentation fault.
The symptoms are similar as described here:
Qt QString cloning Segmentation Fault

The SIGSEGV originates from QBasicAtomicInt::ref, coming from QString::QString(const QString &other).

It seems to me as if there is an attempt to copy an invalid QString within a copy constructor. It is my understanding, that the QString keeps a pointer to its content as long as there is a valid reference to it. If a copy of MyException instance is being made, is it not true that the temporary stack instance has not left the scope and the copy should succeed?

When I implement MyException without a QString member, everything work well.

  • 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-04T16:36:22+00:00Added an answer on June 4, 2026 at 4:36 pm

    The answer to the question is “Yes, a QString can safely be a member in an exception.”

    The problems which I encountered were due to the fact that the object, acting as a source of data for the fDescription, had a bug. It implemented a getter method:

    class Source
    {
    private: QString fData;
    public:  QString GetData(void) { this->fData; }   // There is a missing return
    }
    

    Of course, the result of this call was the random value residing on the stack at the moment and hence the SIGSEGV.

    The QString behaves as expected and with a valid reference to it, there are no problems using it in the exception.

    The precise point where the SIGSEGV was raised was leaving the scope of the try block, where a copy of the exception is being constructed (remember: throw by value, catch by reference). The default copy constructor tries to create a shallow copy of all members and fails on accessing the invalid QString reference.

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

Sidebar

Related Questions

I'm developing a web project where i need to add custom exception classes. For
I developing a custom manager class with chainable method. Got a problem. I need
I am developing custom component derived from TCustomControl class. I would like to add
I am developing a custom shopping cart for which existing customers will need to
I'm currently developing a custom control that derives from CStatic MFC class (Smart Device
I'm developing a custom WordPress theme for a company, and I'd like to keep
I'm developing custom Agent for LotusNotes 8.5. I'd like to use iCal4j jar to
I am developing a custom LISP interpreter. It won't support defining functions like in
I'm developing a few custom ant tasks that all need to initialize the same
im developing a custom form and i need to put a button right next

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.