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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:24:34+00:00 2026-05-16T12:24:34+00:00

Here is the code of my simple tray application. It crashes with segfault when

  • 0

Here is the code of my simple tray application. It crashes with segfault when i call information window from context menu of application and then close it.
I’ve tryed different variants to find a reason of segfault, this is my last try.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
from PyQt4 import QtCore
from PyQt4 import QtGui    

class SystemTrayIcon(QtGui.QSystemTrayIcon):
    def __init__(self, parent=None):
        QtGui.QSystemTrayIcon.__init__(self, parent)

        self.setIcon(QtGui.QIcon("icon.png"))

        self.iconMenu = QtGui.QMenu(parent)
        appabout = self.iconMenu.addAction("About")
        appexit = self.iconMenu.addAction("Exit")
        self.setContextMenu(self.iconMenu)

        self.aboutdialog = QtGui.QWidget(parent)

        self.connect(appabout,QtCore.SIGNAL('triggered()'),self.showAbout)
        self.connect(appexit,QtCore.SIGNAL('triggered()'),self.appExit)

        self.show()


    def showAbout(self):
        QtGui.QMessageBox.information(self.aboutdialog, self.tr("About Tunarium"), self.tr("Your text here."))

    def appExit(self):
        sys.exit()


if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)

    trayIcon = SystemTrayIcon()
    trayIcon.show()

    sys.exit(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-16T12:24:34+00:00Added an answer on May 16, 2026 at 12:24 pm

    I don’t know Python but in your appExit(), you should be calling quit() or exit() on the application object which will cause your call to sys.exit(app.exec_()) in main to return. Again, not knowing the Python specifics, you can do this by using the Qt macro qApp and call qApp->quit() or QCoreApplication::instance()->quit().

    Calling quit() is the same as calling exit(0). You can use exit() directly to return any exit code of your choice.

    Update:
    I’ve tried your code in C++ with a few tweaks and it does work. I’ve commented where you should try making changes to your code. Hope it works for you.

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    
    import sys
    from PyQt4 import QtCore
    from PyQt4 import QtGui    
    
    class SystemTrayIcon(QtGui.QSystemTrayIcon):
        def __init__(self, parent=None):
            QtGui.QSystemTrayIcon.__init__(self, parent)
    
            self.setIcon(QtGui.QIcon("icon.png"))
    
            self.iconMenu = QtGui.QMenu(parent)
            appabout = self.iconMenu.addAction("About")
            appexit = self.iconMenu.addAction("Exit")
            self.setContextMenu(self.iconMenu)
    
            # Remove this next line, it isn't needed
            #self.aboutdialog = QtGui.QWidget(parent)
    
            self.connect(appabout,QtCore.SIGNAL('triggered()'),self.showAbout)
            self.connect(appexit,QtCore.SIGNAL('triggered()'),self.appExit)
    
            # Remove this next line, it isn't needed
            #self.show()
    
    
        def showAbout(self):
            # Before showing the message box, disable the tray icon menu
            self.iconMenu.setEnabled(false)
            # Replace self.aboutdialog with the Python equivalent of null (0?)
            QtGui.QMessageBox.information(0, self.tr("About Tunarium"), self.tr("Your text here."))
            # Re-enable the tray icon menu
            self.iconMenu.setEnabled(true)
    
        def appExit(self):
            # Replace the next line with something that calls the QApplication's
            #   exit() or quit() function.
            #sys.exit()
            app.quit()
    
    
    if __name__ == "__main__":
        app = QtGui.QApplication(sys.argv)
        # Tell the application not to exit when the last window is closed. This should 
        # prevent the application from exiting when the message box is closed.
        app.setQuitOnLastWindowClosed(false)
    
        trayIcon = SystemTrayIcon()
        trayIcon.show()
    
        sys.exit(app.exec_())
    

    Update 2:

    As requested, here is the equivalent C++ code:

    main.cpp

    #include <QtGui/QApplication>
    
    #include "SystemTrayIcon.h"
    
    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv);
        app.setQuitOnLastWindowClosed(false);
        SystemTrayIcon trayIcon(&app);
        trayIcon.show();
    
        return app.exec();
    }
    

    SystemTrayIcon.h

    #ifndef SYSTEMTRAYICON_H
    #define SYSTEMTRAYICON_H
    
    #include <QtGui/QSystemTrayIcon>
    #include <QtGui/QAction>
    #include <QtGui/QMenu>
    #include <QtGui/QWidget>
    
    class SystemTrayIcon : public QSystemTrayIcon
    {
        Q_OBJECT
    
    public:
        SystemTrayIcon(QObject * parent = 0);
        virtual ~SystemTrayIcon();
    
    private:
        QAction * m_appabout;
        QAction * m_appexit;
        QMenu * m_iconMenu;
        QWidget * m_aboutdialog;
    
    private slots:
        void slot_showAbout();
        void slot_exit();
    };
    
    #endif  /* SYSTEMTRAYICON_H */
    

    SystemTrayIcon.cpp

    #include <iostream>
    #include <QtCore/QCoreApplication>
    #include <QtGui/QIcon>
    #include <QtGui/QAction>
    #include <QtGui/QMessageBox>
    
    #include "SystemTrayIcon.h"
    
    SystemTrayIcon::SystemTrayIcon(QObject * parent) :
        QSystemTrayIcon(parent),
        m_appabout(0),
        m_appexit(0),
        m_iconMenu(0),
        m_aboutdialog(0)
    {
        setIcon(QIcon("icon.png"));
    
        m_iconMenu = new QMenu();
        m_appabout = m_iconMenu->addAction("About");
        m_appexit = m_iconMenu->addAction("Exit");
        setContextMenu(m_iconMenu);
    
        connect(m_appabout, SIGNAL(triggered()), this, SLOT(slot_showAbout()));
        connect(m_appexit, SIGNAL(triggered()), this, SLOT(slot_exit()));
    }
    
    SystemTrayIcon::~SystemTrayIcon()
    {
    }
    
    void SystemTrayIcon::slot_showAbout()
    {
        std::cout << "slot show about." << std::endl;
        m_iconMenu->setEnabled(false);
        QMessageBox::information(0, "About Tunarium", "Your text here.");
        m_iconMenu->setEnabled(true);
    }
    
    void SystemTrayIcon::slot_exit()
    {
        std::cout << "slot exit." << std::endl;
        qApp->quit();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.