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

  • SEARCH
  • Home
  • 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 6143839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:34:22+00:00 2026-05-23T18:34:22+00:00

I’m new to Qt. So I started to reimplement one of the get started

  • 0

I’m new to Qt. So I started to reimplement one of the get started examples: link.

However I get a SIGABRT signal when closing the windows. The reason for this is obvoisly due to some memory managment error.

Below you find the callstack and the relevant code. The line editWindow.setLayout(&layout); causes the error. Is the layout class deleting widgets on destruction, therefor claiming ownership of them?

Whats the reaon for this behavior? And how to fix it?

Best regards.

information
callstack
callstack

source

  QPushButton testButton("Test");

  QVBoxLayout layout;
  layout.addWidget(&testButton);

  QWidget editWindow;
  // the following line is the source of the error
  editWindow.setLayout(&layout);
  editWindow.show();

  int val = app.exec();
  • 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-23T18:34:22+00:00Added an answer on May 23, 2026 at 6:34 pm

    Many different Qt functions will take ownership of the object being passed in which means it assumes control over all memory management and will free it upon delete. From the setLayout docs:

    The QWidget will take ownership of layout.

    After you have called setLayout it has a parent and its parent deletes it in addition to it being deleted when the method’s stack is cleaned up. Thus, it’s being deleted twice which is causing the problems.

    If everything else is correct, this change should fix it:

    QVBoxLayout *layout = new QVBoxLayout();
    //...
    layout->addWidget(&testButton);
    //...
    editWindow.setLayout(layout);
    

    Also, note that it’s typical to create the main widget and then assign widgets that will be displayed on that widget as the parent. In other words, I’d expect something more like the following (though not strictly necessary). This also helps assure that if something does get reparented in the future you won’t have problems:

    QWidget editWindow;
    QVBoxLayout *layout = new QVBoxLayout();
    QPushButton *testButton = new QPushButton(&editWindow);
    layout->addWidget(testButton);
    editWindow.setLayout(layout);
    editWindow.show();
    int val = app.exec();
    

    Most Qt objects which are reparented and to which ownership changes may happen will have a constructor that accepts a QWidget* or QObject*.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I have this code to decode numeric html entities to the UTF8 equivalent character.
This could be a duplicate question, but I have no idea what search terms

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.