Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QDialog crashing on importing QLayout
Qt 6.11 is out! See what's new in the release blog

QDialog crashing on importing QLayout

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 455 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Dummie1138D Offline
    Dummie1138D Offline
    Dummie1138
    wrote on last edited by
    #1

    Hi. I have the following code:

    QString CCCFPMenuBar::passwordReader(){
        //Create a layout involving a label, password, a line edit and submit button
        QVBoxLayout layout(this);
        QLabel passwordLabel("Password:");
        QPushButton submitButton;
        QLineEdit password;
        //Create a box with that layout
        QDialog passwordDialog(this);
        layout.addWidget(&passwordLabel);
        layout.addWidget(&submitButton);
        layout.addWidget(&password);
        qDebug() << "83";
        passwordDialog.setLayout(&layout);
        //passwordDialog.exec();
        return "AHHHHH";
    

    The code crashes at passwordDialog.setLayout(&layout); but I am unsure why. My syntax from the QLayout seems accurate based on my understanding, and the QLayout doesn't seem (again, in my understanding) to be invalid for QDialog.

    Thanks for your time and please let me know if more information is required.

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      A widget takes ownership of a layout and its child widgets, meaning it deletes them when it is itself deleted (or goes out of scope when created on the stack). This means you shouldn't create the layout or the widgets on the stack, as you get a double delete problem - once by the parent and once by going out of scope.

      1 Reply Last reply
      3

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved