Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

SystemTray crashing on icon click. I have zero idea what may be causing this. Can someone help?



  • When my system tray successfully appears in the tray, after I click it, it crashes with this error:

    I am a wall and stuck. Can someone help me out here?

    Application Specific Information:
    objc_msgSend() selector name: _associateStatusItem:
    
    
    Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
    0   libobjc.A.dylib               	0x00007fff9247b4dd objc_msgSend + 29
    1   com.apple.AppKit              	0x00007fff91b82df4 -[NSStatusItem popUpStatusItemMenu:] + 36
    2   com.apple.AppKit              	0x00007fff91c733c9 -[NSWindow _handleMouseDownEvent:isDelayedEvent:] + 6322
    3   com.apple.AppKit              	0x00007fff91c743ad -[NSWindow _reallySendEvent:isDelayedEvent:] + 212
    4   com.apple.AppKit              	0x00007fff916b3539 -[NSWindow sendEvent:] + 517
    5   com.apple.AppKit              	0x00007fff91b81849 -[NSStatusBarWindow sendEvent:] + 281
    6   com.apple.AppKit              	0x00007fff91633a38 -[NSApplication sendEvent:] + 2540
    7   libqcocoa.dylib               	0x000000010754120a 0x107513000 + 188938
    8   com.apple.AppKit              	0x00007fff9149adf2 -[NSApplication run] + 796
    9   libqcocoa.dylib               	0x000000010753d91d 0x107513000 + 174365
    10  org.qt-project.QtCore         	0x00000001044e9a51 QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) + 417
    11  org.qt-project.QtCore         	0x00000001044ee7f8 QCoreApplication::exec() + 392
    12  com.yourcompany.ChronoGraff   	0x00000001037e095b main + 1467
    13  libdyld.dylib                 	0x00007fff9109b5ad start + 1
    

    This is header:

    /*
    *
    * @Author: 				Darran Thompson
    * @Date:   				2018-03-31 23:00:19
    * @Last Modified by:   	Darran Thompson
    * @Last Modified time: 	2018-04-07 16:31:59
    *
    * @Company:				Darran Thompson
    *
    * Darran Thompson
    * __________________
    *
    * Copyright (C) Darran Thompson - All Rights Reserved
    * Unauthorized copying of this file, via any medium is strictly prohibited
    * Proprietary and confidential
    *
    */
    
    #ifndef SYSTEM_TRAY_H
    #define SYSTEM_TRAY_H 1
    
    #include <stdlib.h>
    #include <stdio.h>
    
    #include <memory>
    
    #include <QSystemTrayIcon>
    #include <QDialog>
    #include <QAction>
    #include <QCheckBox>
    #include <QComboBox>
    #include <QCoreApplication>
    #include <QCloseEvent>
    #include <QGroupBox>
    #include <QLabel>
    #include <QLineEdit>
    #include <QMenu>
    #include <QPushButton>
    #include <QSpinBox>
    #include <QTextEdit>
    #include <QVBoxLayout>
    #include <QMessageBox>
    #include <QShortcut>
    #include <QKeySequence>
    
    #include <include/ui/requested.h>
    #include <include/ui/scheduled.h>
    #include <include/ui/notify.h>
    
    class QAction;
    class QCheckBox;
    class QComboBox;
    class QGroupBox;
    class QLabel;
    class QLineEdit;
    class QMenu;
    class QPushButton;
    class QSpinBox;
    class QTextEdit;
    
    class Requested;
    class Scheduled;
    class Notify;
    
    class SystemTray : public QDialog
    {
        Q_OBJECT
    
    public:
    
        SystemTray();
    
    public slots:
    
    private slots:
    
        void onActivated(QSystemTrayIcon::ActivationReason reason);
        void showMessage();
        void showRequested();
        void showScheduled();
        void showNotify();
    
    protected:
    
        void closeEvent(QCloseEvent * event) override;
    
    private:
    
        void createActions();
        void createTrayIcon();
    
        QAction * requested_action = nullptr;
        QAction * scheduled_action = nullptr;
        QAction * notify_action = nullptr;
        QAction * resume_work_action = nullptr;
        QAction * view_tasks_action = nullptr;
        QAction * scan_workstation_actions = nullptr;
        QAction * quit_action = nullptr;
    
        QSystemTrayIcon * tray_icon = nullptr;
        QMenu * tray_icon_menu = nullptr;
    
        std::unique_ptr<Requested> requested = nullptr;
        std::unique_ptr<Scheduled> scheduled = nullptr;
        std::unique_ptr<Notify> notify = nullptr;
    
        bool opened;
    };
    
    #endif // SYSTEM_TRAY_H
    

    And the source:

    /*
    *
    * @Author: 				Darran Thompson
    * @Date:   				2018-03-31 23:00:08
    * @Last Modified by:   	Darran Thompson
    * @Last Modified time: 	2018-04-07 16:42:08
    *
    * @Company:				Darran Thompson
    *
    * Darran Thompson
    * __________________
    *
    * Copyright (C) Darran Thompson - All Rights Reserved
    * Unauthorized copying of this file, via any medium is strictly prohibited
    * Proprietary and confidential
    *
    */
    
    #include <include/ui/system_tray.h>
    
    SystemTray::SystemTray() : opened{false}
    {
        // createIconGroupBox();
        // createMessageGroupBox();
    
        // iconLabel->setMinimumWidth(durationLabel->sizeHint().width());
    
        createActions();
        createTrayIcon();
    
        // connect(showMessageButton, &QAbstractButton::clicked, this, &SystemTray::showMessage);
        // connect(showIconCheckBox, &QAbstractButton::toggled, tray_icon, &QSystemTrayIcon::setVisible);
        // connect(iconComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
        //         this, &SystemTray::setIcon);
        // connect(tray_icon, &QSystemTrayIcon::messageClicked, this, &SystemTray::messageClicked);
        // connect(tray_icon, &QSystemTrayIcon::activated, this, &SystemTray::iconActivated);
    
        // QVBoxLayout *mainLayout = new QVBoxLayout;
        // mainLayout->addWidget(iconGroupBox);
        // mainLayout->addWidget(messageGroupBox);
        // setLayout(mainLayout);
    
        // // iconComboBox->setCurrentIndex(1);
        tray_icon->show();
    
        // setWindowTitle(tr("Systray"));
        // resize(400, 300);
    
        // connect(tray_icon, &QSystemTrayIcon::activated, this, &SystemTray::onActivated);
    }
    
    void SystemTray::closeEvent(QCloseEvent * event)
    {
    }
    
    void SystemTray::onActivated(QSystemTrayIcon::ActivationReason reason)
    {
        switch (reason) {
        case QSystemTrayIcon::Trigger: {
            } break;
        case QSystemTrayIcon::DoubleClick:{
            } break;
        case QSystemTrayIcon::MiddleClick:{
                showMessage();
            } break;
        default:{
        	};
        }
    }
    
    void SystemTray::showMessage()
    {
        QSystemTrayIcon::MessageIcon msgIcon = QSystemTrayIcon::MessageIcon(QSystemTrayIcon::Information);
        tray_icon->showMessage(tr("Title"), tr("Stop"), msgIcon, 1000);
    }
    
    void SystemTray::showRequested()
    {
    	if (requested == nullptr)
    	{
    		requested = std::unique_ptr<Requested>{new Requested};
    	}
    
    	requested->show();
    	opened = requested->isVisible();
    	std::cout << opened << std::endl;
    }
    
    void SystemTray::showScheduled()
    {
    	if (scheduled == nullptr)
    	{
    		scheduled = std::unique_ptr<Scheduled>{new Scheduled};
    	}
    
    	scheduled->show();
    }
    
    void SystemTray::showNotify()
    {
    	if (notify == nullptr)
    	{
    		notify = std::unique_ptr<Notify>{new Notify};
    	}
    
    	notify->show();
    }
    
    void SystemTray::createActions()
    {
        requested_action = new QAction(tr("Request time away"), this);
        connect(requested_action, &QAction::triggered, this, &SystemTray::showRequested);
    
        scheduled_action = new QAction(tr("Schedule a break"), this);
        connect(scheduled_action, &QAction::triggered, this, &SystemTray::showScheduled);
    
        notify_action = new QAction(tr("Notify brief timeout"), this);
        connect(notify_action, &QAction::triggered, this, &SystemTray::showNotify);
    
        quit_action = new QAction(tr("&Quit"), this);
        quit_action->setShortcut(QKeySequence::Quit);
        connect(quit_action, &QAction::triggered, qApp, &QCoreApplication::quit);
    
        resume_work_action = new QAction(tr("Resume work"));
        resume_work_action->setEnabled(false);
        view_tasks_action = new QAction(tr("View daily tasks"));
        scan_workstation_actions = new QAction(tr("Scan workstation for ISO breach"));
    }
    
    void SystemTray::createTrayIcon()
    {
        tray_icon_menu = new QMenu(this);
        tray_icon_menu->addAction(requested_action);
        tray_icon_menu->addAction(scheduled_action);
        tray_icon_menu->addAction(notify_action);
        tray_icon_menu->addSeparator();
        tray_icon_menu->addAction(resume_work_action);
        tray_icon_menu->addSeparator();
        tray_icon_menu->addAction(view_tasks_action);
        tray_icon_menu->addAction(scan_workstation_actions);
        tray_icon_menu->addSeparator();
        tray_icon_menu->addAction(quit_action);
    
        QIcon icon(":/res/chronograff.tiff");
        tray_icon = new QSystemTrayIcon(icon);
        tray_icon->setContextMenu(tray_icon_menu);
    }
    
    


  • Have no idea how it solved. It has just started playing right.

    ....head scratching!


  • Moderators

    @ChronoG said in SystemTray crashing on icon click. I have zero idea what may be causing this. Can someone help?:

    Have no idea how it solved. It has just started playing right.

    ....head scratching!

    Usually that's a dirty build then. If nothing changed and it just starts "working right" then you had a bad build before. Rebuilding at some point fixed it. :)


Log in to reply