I have successfully created a system tray icon with this program. However, I'm running into a bit of a snag.
If you haven't figured out by now, I'm a bit of a noob to QT and KDE programming, but am learning with all the documentation I've found. With that said I'll dive into the issue at hand.
I have figured out how to add items to the KPopupMenu (context menu of KSystemTray), but I am having issues with adding my own custom SLOTS when inheriting off of KPopupMenu. For now I have taken out the feeble attempts at inheriting off of KPopupMenu, as KSystemTray expects only a KPopupMenu, and not a subclass of it.
Code:
#include <kapplication.h>
#include <ksystemtray.h>
#include <kcmdlineargs.h>
#include <qpixmap.h>
#include <kpopupmenu.h>
#include "kickertest.h"
int main( int argc, char **argv ) {
KApplication q( argc, argv, "Systemtray Test" );
KickerTest *wid = new KickerTest( );
//Create Instance of KSystemTray
KSystemTray *tray = new KSystemTray( wid, "Systemtray Test" );
QPixmap tmp("/opt/kde/share/icons/crystalsvg/22x22/apps/agent.png");
KPopupMenu *menu = tray->contextMenu();
menu->changeTitle(0, NULL, "Testing");
menu->insertTitle("Testing",1,1);
menu->insertItem( "&Test", menu, SLOT(button_clicked()) );
tray->setPixmap( tmp );
tray->show( );
q.setMainWidget( wid );
return q.exec( );
}
This code works okay, except that the "Test" item does nothing, and the system spits out the following error:
Code:
QObject::connect: No such slot KPopupMenu::button_clicked()
Creating a subclass for a widget or something to that effect would be a lot easier to do, but that's for creating a File, Edit, etc. menu.
I'd appreciate any suggestions on how to add slots for a systemtray application, thanks!