ich versuche grad das trayicon in mein source zu intregrieren es klappt momentan noch nicht.
ich habe für mein Mainwindow das dazu gehörigespecs\win32-g++" -o release\trayicon_win.o trayicon\trayicon_win.cpp
trayicon\trayicon_win.cpp: In member function `bool TrayIcon::TrayIconPrivate::t
rayMessageA(DWORD)':
trayicon\trayicon_win.cpp:95: error: `QMIN' undeclared (first use this function)
trayicon\trayicon_win.cpp:95: error: (Each undeclared identifier is reported onl
y once for each function it appears in.)
trayicon\trayicon_win.cpp: In member function `bool TrayIcon::TrayIconPrivate::t
rayMessageW(DWORD)':
trayicon\trayicon_win.cpp:124: error: `QMIN' undeclared (first use this function
)
mingw32-make[1]: *** [release\trayicon_win.o] Error 1
mingw32-make[1]: Leaving directory `E:/test'
mingw32-make: *** [release] Error 2
MainWindowtrayicon.cpp und .h erstellt.
hier mein MainWindow.cpp
Code: Alles auswählen
#include <QString>
#include <QtDebug>
#include <QIcon>
#include "MainWindow.h"
#include "Preferences/PreferencesWindow.h"
#include "MainWindowtrayicon.h"
#define FONT QFont(tr("Arial"), 8)
/* Images for toolbar icons */
#define IMAGE_CONNECTIONS ":/images/connections_24x24.png"
#define IMAGE_PEERS ":/images/peers_24x24.png"
#define IMAGE_SEARCH ":/images/search_24x24.png"
#define IMAGE_DOWNLOADS ":/images/downloads_24x24.png"
#define IMAGE_SHARED_FILES ":/images/sharedfiles_24x24.png"
#define IMAGE_UPLOADS ":/images/uploads_24x24.png"
#define IMAGE_PREFERENCES ":/images/preferences_24x24.png"
#define IMAGE_CHAT ":/images/chats_24x24.png"
/** Constructor */
MainWindow::MainWindow(QWidget* parent)
: QMainWindow(parent)
{
/* Invoke the Qt Designer generated QObject setup routine */
ui.setupUi(this);
/* Create the config pages and actions */
QActionGroup *grp = new QActionGroup(this);
ui.stackPages->add(new ConnectionsDialog(ui.stackPages),
createPageAction(QIcon(IMAGE_CONNECTIONS), tr("Connections"), grp));
ui.stackPages->add(new PeersDialog(ui.stackPages),
createPageAction(QIcon(IMAGE_PEERS), tr("Peers"), grp));
ui.stackPages->add(new SearchDialog(ui.stackPages),
createPageAction(QIcon(IMAGE_SEARCH), tr("Search"), grp));
ui.stackPages->add(new DownloadsDialog(ui.stackPages),
createPageAction(QIcon(IMAGE_DOWNLOADS), tr("Downloads"), grp));
ui.stackPages->add(new UploadsDialog(ui.stackPages),
createPageAction(QIcon(IMAGE_UPLOADS), tr("Uploads"), grp));
ui.stackPages->add(new ChatDialog(ui.stackPages),
createPageAction(QIcon(IMAGE_CHAT), tr("Chat"), grp));
ui.stackPages->add(new SharedFilesDialog(ui.stackPages),
createPageAction(QIcon(IMAGE_SHARED_FILES), tr("Shared Files"), grp));
/* Create the toolbar */
ui.toolBar->addActions(grp->actions());
ui.toolBar->addSeparator();
connect(grp, SIGNAL(triggered(QAction *)), ui.stackPages, SLOT(showPage(QAction *)));
/* Create and bind the Preferences button */
addAction(new QAction(QIcon(IMAGE_PREFERENCES), tr("Preferences"), ui.toolBar),
SLOT(PreferencesWindow()));
/* Select the first action */
grp->actions()[0]->setChecked(true);
// show the tray Icon
setupTrayIcon();
}
/** Creates a new action associated with a config page. */
QAction*
MainWindow::createPageAction(QIcon img, QString text, QActionGroup *group)
{
QAction *action = new QAction(img, text, group);
action->setCheckable(true);
action->setFont(FONT);
return action;
}
/** Adds the given action to the toolbar and hooks its triggered() signal to
* the specified slot (if given). */
void
MainWindow::addAction(QAction *action, const char *slot)
{
action->setFont(FONT);
ui.toolBar->addAction(action);
connect(action, SIGNAL(triggered()), this, slot);
}
/** Overloads the default show so we can load settings */
void
MainWindow::show()
{
if (!this->isVisible()) {
QMainWindow::show();
} else {
QMainWindow::activateWindow();
setWindowState(windowState() & ~Qt::WindowMinimized | Qt::WindowActive);
QMainWindow::raise();
}
}
/** Shows the config dialog with focus set to the given page. */
void
MainWindow::show(Page page)
{
/* Show the dialog. */
show();
/* Set the focus to the specified page. */
ui.stackPages->setCurrentIndex((int)page);
}
/** Shows Preferences */
/**void MainWindow::showPreferencesWindow()
{
PreferencesWindow *preferencesWindow = new PreferencesWindow();
preferencesWindow->exec();
}
*/
void MainWindow::setupTrayIcon()
{
/**
@todo: Why doesn't the resource path work here? :/resources/hi24.png
*/
// create the pixmap
QPixmap pixmap = QPixmap(":/images/r16.png");
// create the menu
QMenu *menu = new QMenu( QCoreApplication::instance()->applicationName() );
// add a horizontal line to the menu
menu->addSeparator();
// add actions to the menu
actionTrayRestore = menu->addAction( tr("Restore from Tray"));
//actionTrayRestore->setIcon(QIcon(":/window_list.png"));
// if kommute is visible, disable the actionTrayRestore
// until a valid method is implemented here, set to false as standard
actionTrayRestore->setEnabled( false );
connect( actionTrayRestore, SIGNAL( triggered() ), this, SLOT( restoreMainWindow() ));
// add a horizontal line to the menu
menu->addSeparator();
// add the close menu entry
actionTrayExit = menu->addAction( tr("Close"));
//actionTrayExit->setIcon(QIcon(":/exit.png"));
connect( actionTrayExit, SIGNAL( triggered() ), this, SLOT( close() ));
// build the trayicon
trayIcon = new MainWindowTrayIcon( pixmap, QCoreApplication::instance()->applicationName(), menu, this );
// show the icon
trayIcon->show();
}
Code: Alles auswählen
#ifndef _MainWindow_H
#define _MainWindow_H
#include <QMainWindow>
#include <QFileDialog>
#include "ConnectionsDialog.h"
#include "PeersDialog.h"
#include "SearchDialog.h"
#include "DownloadsDialog.h"
#include "UploadsDialog.h"
#include "ChatDialog.h"
#include "SharedFilesDialog.h"
#include "ui_MainWindow.h"
class QAction;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
/** Main dialog pages. */
enum Page {
Connections = 0, /** Connections page. */
Peers = 1, /** Peers page. */
Search = 2, /** Search page. */
Downloads = 3, /** Downloads page. */
Uploads = 4, /** Uploads page. */
Chat = 5, /** Chats page. */
SharedFiles = 6 /** Shared Files page. */
};
/** Default Constructor */
MainWindow(QWidget *parent = 0);
public slots:
/** Called when this dialog is to be displayed */
void show();
/** Shows the config dialog with focus set to the given page. */
void show(Page page);
private slots:
/** Called when user clicks "Help" */
/**void preferences();*/
void restoreMainWindow();
private:
/** Creates a new action for a config page. */
QAction* createPageAction(QIcon img, QString text, QActionGroup *group);
/** Adds a new action to the toolbar. */
void addAction(QAction *action, const char *slot = 0);
void setupTrayIcon();
void removeTrayIcon();
class MainWindowTrayIcon *trayIcon;
// actions for systray icon
class QAction *actionTrayExit;
class QAction *actionTrayRestore;
/** Qt Designer generated object */
Ui::MainWindow ui;
};
#endif
Code: Alles auswählen
#include "MainWindowtrayicon.h"
MainWindowTrayIcon::MainWindowTrayIcon( const QPixmap &icon, const QString &tooltip, QMenu *popup, QObject *parent )
: TrayIcon( icon, tooltip, popup, parent )
{
/**
Nothing needs to be done here, this function is only to have a constructor for this class
All values are passed to TrayIcon.
parent and popup are set by default to 0.
*/
}
MainWindowTrayIcon::~MainWindowTrayIcon()
{
// standard destructor for this class.
// Do we need some functionality here ?
}Code: Alles auswählen
#ifndef MAINWINDOWTRAYICON_H
#define MAINWINDOWTRAYICON_H
#include "trayicon/trayicon.h"
class MainWindowTrayIcon : public TrayIcon
{
/*
this class is only to overwrite some function if this is needed
*/
public:
MainWindowTrayIcon( const QPixmap &icon, const QString &tooltip, QMenu *popup = 0, QObject *parent = 0 );
~MainWindowTrayIcon();
};
#endif
Code: Alles auswählen
#include "MainWindow.h"
int main( int argc, char ** argv )
{
QApplication app( argc, argv ); // QT's GUI-Funktionalität initialisieren
MainWindow w; // hier erst wird dein MainWindow erzeugt
w.show();
return app.exec();
}