trayicon errors

Alles rund um die Programmierung mit Qt
Antworten
defenderLQ
Beiträge: 156
Registriert: 27. Juli 2006 20:53

trayicon errors

Beitrag von defenderLQ »

hi

ich versuche grad das trayicon in mein source zu intregrieren es klappt momentan noch nicht.
specs\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
ich habe für mein Mainwindow das dazu gehörige
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();
}
    
und die dazugehörige MainWindow.h

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

MainWindowtrayicon.cpp

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 ?
}
MainWindowtrayicon.h:

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
hier mein Main.cpp:

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();
}
also ich habe das ganze nach einem beispiel gemacht.
Christian81
Beiträge: 7319
Registriert: 26. August 2004 14:11
Wohnort: Bremen
Kontaktdaten:

Beitrag von Christian81 »

Woher hast Du trayicon_win.cpp - ist zumindest nicht bei Qt3/4 dabei...? QMIN und QMAX gibt es in Qt4 nicht mehr / bzw. nur wenn mit QT3_SUPPORT. Sie heissen jetzt QMin und QMax.
MfG Christian

'Funktioniert nicht' ist keine Fehlerbeschreibung
defenderLQ
Beiträge: 156
Registriert: 27. Juli 2006 20:53

Beitrag von defenderLQ »

ich habs vom opensource anwendung PSi .
ist also GPL lizenz.
ist für QT4 .

habe im _win.cpp
zu QMin geändert aber bringt nichts:

Code: Alles auswählen

/*
 * trayicon_win.cpp - Windows trayicon, adapted from Qt example
 * Copyright (C) 2003  Justin Karneges
 * Qt4 port: Stefan Gehn
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

#include "trayicon.h"

#include <qwidget.h>
#include <qapplication.h>
#include <qimage.h>
#include <qpixmap.h>
#include <qpainter.h>
#include <qbitmap.h>
#include <qcursor.h>
#include <qlibrary.h>

#include <qt_windows.h>

static uint WM_TASKBARCREATED = 0;
#define WM_NOTIFYICON	(WM_APP+101)

typedef BOOL (WINAPI *PtrShell_NotifyIcon)(DWORD,PNOTIFYICONDATA);
static PtrShell_NotifyIcon ptrShell_NotifyIcon = 0;

static void resolveLibs()
{
	QLibrary lib("shell32");
	//lib.setAutoUnload( FALSE );
	static bool triedResolve = FALSE;
	if ( !ptrShell_NotifyIcon && !triedResolve )
	{
		triedResolve = TRUE;
		ptrShell_NotifyIcon = (PtrShell_NotifyIcon) lib.resolve( "Shell_NotifyIconW" );
	}
}


class TrayIcon::TrayIconPrivate : public QWidget
{
public:
	HICON hIcon;
	TrayIcon *iconObject;

	TrayIconPrivate( TrayIcon *object ) : QWidget( 0 ),
		hIcon( 0 ), iconObject( object )
	{
		if ( !WM_TASKBARCREATED )
			WM_TASKBARCREATED = RegisterWindowMessage( TEXT("TaskbarCreated") );
	}

	~TrayIconPrivate()
	{
		if ( hIcon )
		{
			DestroyIcon( hIcon );
			hIcon = 0;
		}
	}

	// the unavoidable A/W versions. Don't forget to keep them in sync!
	bool trayMessageA( DWORD msg )
	{
		NOTIFYICONDATAA tnd;
		ZeroMemory( &tnd, sizeof(NOTIFYICONDATAA) );
		tnd.cbSize = sizeof(NOTIFYICONDATAA);
		tnd.hWnd = winId();
		tnd.uID = 1;

		if ( msg != NIM_DELETE )
		{
			tnd.uFlags = NIF_MESSAGE|NIF_ICON|NIF_TIP;
			tnd.uCallbackMessage = WM_NOTIFYICON;
			tnd.hIcon = hIcon;

			if ( !iconObject->toolTip().isNull() )
			{
				// Tip is limited to 63 + NULL; lstrcpyn appends a NULL terminator.
				QString tip = iconObject->toolTip().left( 63 ) + QChar();
				lstrcpynA(tnd.szTip, (const char*)tip.toLocal8Bit(), QMin( tip.length()+1, 64 ) );
			}
		}
		return Shell_NotifyIconA(msg, &tnd);
	} // trayMessageA

#ifdef UNICODE
	bool trayMessageW( DWORD msg )
	{
		resolveLibs();
		if ( ! (ptrShell_NotifyIcon && QSysInfo::WindowsVersion & QSysInfo::WV_NT_based) )
			return trayMessageA( msg );

		NOTIFYICONDATAW tnd;
		ZeroMemory( &tnd, sizeof(NOTIFYICONDATAW) );
		tnd.cbSize = sizeof(NOTIFYICONDATAW);
		tnd.hWnd = winId();
		tnd.uID = 1;

		if ( msg != NIM_DELETE )
		{
			tnd.uFlags = NIF_MESSAGE|NIF_ICON|NIF_TIP;
			tnd.uCallbackMessage = WM_NOTIFYICON;
			tnd.hIcon = hIcon;

			if ( !iconObject->toolTip().isNull() )
			{
				// Tip is limited to 63 + NULL; lstrcpyn appends a NULL terminator.
				QString tip = iconObject->toolTip().left( 63 ) + QChar();
				lstrcpynW(tnd.szTip, (TCHAR*)tip.unicode(), QMin( tip.length()+1, 64 ) );
			}
		}
		return ptrShell_NotifyIcon(msg, &tnd);
	} // trayMessageW
#endif

	bool trayMessage( DWORD msg )
	{
		QT_WA(return trayMessageW(msg);, return trayMessageA(msg);)
	}

	bool iconDrawItem(LPDRAWITEMSTRUCT lpdi)
	{
		if (!hIcon)
			return FALSE;

		DrawIconEx(lpdi->hDC, lpdi->rcItem.left, lpdi->rcItem.top, hIcon, 0, 0, 0, NULL, DI_NORMAL );
		return TRUE;
	}

	bool winEvent( MSG * m, long * result )
	{
		switch(m->message)
		{
			case WM_DRAWITEM:
				return iconDrawItem( (LPDRAWITEMSTRUCT)m->lParam );
			case WM_NOTIFYICON:
			{
				QMouseEvent *e = 0;
				QPoint gpos = QCursor::pos();
				switch (m->lParam) {
					case WM_MOUSEMOVE: e = new QMouseEvent( QEvent::MouseMove, mapFromGlobal( gpos ), gpos, Qt::NoButton, Qt::NoButton, QApplication::keyboardModifiers() ); break;
					case WM_LBUTTONDOWN: e = new QMouseEvent( QEvent::MouseButtonPress, mapFromGlobal( gpos ), gpos, Qt::LeftButton, Qt::LeftButton, QApplication::keyboardModifiers() ); break;
					case WM_LBUTTONUP: e = new QMouseEvent( QEvent::MouseButtonRelease, mapFromGlobal( gpos ), gpos, Qt::LeftButton, Qt::LeftButton, QApplication::keyboardModifiers() ); break;
					case WM_LBUTTONDBLCLK: e = new QMouseEvent( QEvent::MouseButtonDblClick, mapFromGlobal( gpos ), gpos, Qt::LeftButton, Qt::LeftButton, QApplication::keyboardModifiers() );	break;
					case WM_RBUTTONDOWN: e = new QMouseEvent( QEvent::MouseButtonPress, mapFromGlobal( gpos ), gpos, Qt::RightButton, Qt::RightButton, QApplication::keyboardModifiers() ); break;
					case WM_RBUTTONUP: e = new QMouseEvent( QEvent::MouseButtonRelease, mapFromGlobal( gpos ), gpos, Qt::RightButton, Qt::RightButton, QApplication::keyboardModifiers() ); break;
					case WM_RBUTTONDBLCLK: e = new QMouseEvent( QEvent::MouseButtonDblClick, mapFromGlobal( gpos ), gpos, Qt::RightButton, Qt::RightButton, QApplication::keyboardModifiers() ); break;
					case WM_MBUTTONDOWN: e = new QMouseEvent( QEvent::MouseButtonPress, mapFromGlobal( gpos ), gpos, Qt::MidButton, Qt::MidButton, QApplication::keyboardModifiers() ); break;
					case WM_MBUTTONUP: e = new QMouseEvent( QEvent::MouseButtonRelease, mapFromGlobal( gpos ), gpos, Qt::MidButton, Qt::MidButton, QApplication::keyboardModifiers() ); break;
					case WM_MBUTTONDBLCLK: e = new QMouseEvent( QEvent::MouseButtonDblClick, mapFromGlobal( gpos ), gpos, Qt::MidButton, Qt::MidButton, QApplication::keyboardModifiers() ); break;
					case WM_CONTEXTMENU: e = new QMouseEvent( QEvent::MouseButtonRelease, mapFromGlobal( gpos ), gpos, Qt::RightButton, Qt::RightButton, QApplication::keyboardModifiers() ); break;
				}

				if ( e )
				{
					bool res = QApplication::sendEvent( iconObject, e );
					delete e;
					return res;
				}
			}
			break;

			default:
				if ( m->message == WM_TASKBARCREATED )
					trayMessage( NIM_ADD );
		}
		return QWidget::winEvent( m, result );
	} // winEvent
}; // class TrayIcon::TrayIconPrivate


static HICON createIcon( const QPixmap &pm )
{
	ICONINFO iconInfo;
	iconInfo.fIcon    = true;
	iconInfo.hbmMask  = pm.createMaskFromColor(Qt::black).toWinHBITMAP();
	iconInfo.hbmColor = pm.toWinHBITMAP(QPixmap::PremultipliedAlpha);

	HICON icon = CreateIconIndirect( &iconInfo );

	DeleteObject(iconInfo.hbmMask);
	iconInfo.hbmMask = 0;

	DeleteObject(iconInfo.hbmColor);
	iconInfo.hbmColor = 0;

	return icon;
}

void TrayIcon::sysInstall()
{
	if ( !d )
	{
		d = new TrayIconPrivate( this );
		d->hIcon = createIcon( pm );
		d->trayMessage( NIM_ADD );
	}
}

void TrayIcon::sysRemove()
{
	if ( d )
	{
		d->trayMessage( NIM_DELETE );
		delete d;
		d = 0;
	}
}

void TrayIcon::sysUpdateIcon()
{
	if ( d )
	{
		if ( d->hIcon )
		{
			DestroyIcon( d->hIcon );
			d->hIcon = 0;
		}
		d->hIcon = createIcon( pm );
		d->trayMessage( NIM_MODIFY );
	}
}

void TrayIcon::sysUpdateToolTip()
{
	if ( d )
		d->trayMessage( NIM_MODIFY );
}
Zuletzt geändert von defenderLQ am 7. August 2006 16:07, insgesamt 1-mal geändert.
Christian81
Beiträge: 7319
Registriert: 26. August 2004 14:11
Wohnort: Bremen
Kontaktdaten:

Beitrag von Christian81 »

Qt 4.2 bringt das auch mit. Dann hat PSI es wohl noch nicht komplett nach Qt4 portiert - kannst Dich ja mal beschweren :)
MfG Christian

'Funktioniert nicht' ist keine Fehlerbeschreibung
defenderLQ
Beiträge: 156
Registriert: 27. Juli 2006 20:53

Beitrag von defenderLQ »

ja es sieht so aus

aber in meinem anderen sourcecode für einen client ist der gleiche trayicon source dabei

bei der anwendung geht es ohne probleme.
FlorianBecker
Beiträge: 1213
Registriert: 2. Dezember 2004 10:54
Kontaktdaten:

Beitrag von FlorianBecker »

Das ist von qtnode die haben ein TrayIcon für Qt4 z.B. Deswegen verweise ich doch auf die Qt4 Klassen.
Christian81
Beiträge: 7319
Registriert: 26. August 2004 14:11
Wohnort: Bremen
Kontaktdaten:

Beitrag von Christian81 »

defenderLQ hat geschrieben:ja es sieht so aus

aber in meinem anderen sourcecode für einen client ist der gleiche trayicon source dabei

bei der anwendung geht es ohne probleme.
Klar - wenn Du meinen Kommentar gelesen hast siehst Du auch warum...
MfG Christian

'Funktioniert nicht' ist keine Fehlerbeschreibung
defenderLQ
Beiträge: 156
Registriert: 27. Juli 2006 20:53

Beitrag von defenderLQ »

ok dann warte ich mal ab bis QT 4.2 rauskommt.
systray ist momentan nicht so wichtig.
FlorianBecker
Beiträge: 1213
Registriert: 2. Dezember 2004 10:54
Kontaktdaten:

Beitrag von FlorianBecker »

Das TrayIcon von qtnode ist schon vollständig auf Qt4 und steht unter LGPL!

http://www.qtnode.net/wiki/Systray
defenderLQ
Beiträge: 156
Registriert: 27. Juli 2006 20:53

Beitrag von defenderLQ »

danke
werde es mir anschauen....

bei QSystemTrayIcon Class für QT 4.2
wird dann keine externe trayicon source mehr benötigt?
also das ich in mein MainWindow.cpp
es intregrieren muss und schon ist es für
win,linux und mac nutzbar?
Zuletzt geändert von defenderLQ am 7. August 2006 21:51, insgesamt 1-mal geändert.
FlorianBecker
Beiträge: 1213
Registriert: 2. Dezember 2004 10:54
Kontaktdaten:

Beitrag von FlorianBecker »

genau
Antworten