Skip to content

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
    • Help
    • Support
    • Submit feedback
    • Contribute to GitLab
  • Sign in
beat.editor
beat.editor
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 11
    • Issues 11
    • List
    • Boards
    • Labels
    • Milestones
  • Merge Requests 0
    • Merge Requests 0
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Analytics
    • Analytics
    • CI / CD
    • Repository
    • Value Stream
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • beat
  • beat.editorbeat.editor
  • Issues
  • #248

Closed
Open
Opened Sep 16, 2019 by Samuel GAIST@samuel.gaist
  • Report abuse
  • New issue
Report abuse New issue

QMenu for push button lifetime issue

Summary

While doing tests to check whether PySide2 could be used, an issue has been found with the handling of QMenu when used in a helper function to generate a QPushButton, the related QMenu and QActions.

On return of the method, the QMenu object is destroyed with PySide2 while not with PyQt5.

This is likely related to the fact that QPushButton::setMenu does not take ownership of the QMenu. So it likely is garbage collected at the end of the method.

Steps to reproduce

import sys

from PySide2.QtWidgets import QApplication
from PySide2.QtWidgets import QAction
from PySide2.QtWidgets import QMenu
from PySide2.QtWidgets import QPushButton


def build_button_with_menu():
    button = QPushButton("The button")
    menu = QMenu("The menu")
    button.setMenu(menu)
    action = menu.addAction("The action")
    return button, action

app = QApplication(sys.argv)
button, action = build_button_with_menu()
action.triggered.connect(app.quit)
sys.exit(app.exec_())

What is the current bug behavior?

This will trigger a property error saying that triggered has no connect property. Checking the action itself will show the correct type but the signal object related methods will be missing.

What is the expected correct behavior?

No error, the connection gets created, the button is shown and when clicking on the action, the application should stop.

Possible fixes

The fix is to give the QMenu a parent, in this case, the button itself, so its lifetime doesn't end with the end of the method.

Assignee
Assign to
[v2] 1 - Edition/Visualization for small editors
Milestone
[v2] 1 - Edition/Visualization for small editors
Assign milestone
Time tracking
None
Due date
None
4
Labels
bug confirmed critical E dataformat
Assign labels
  • View project labels
Reference: beat/beat.editor#248