PDA

View Full Version : QSystemTrayIcon Problem



SNZ
30th June 2012, 23:13
Hi friends,


when i use QSystemTrayIcon example on Simulator, it's work. but if i compile for Symbain Device on Symbian Build section, i give error : 'QSystemTrayIcon' was not declared in this scope. But i was declared on mainwindow.h and also mainwindow.cpp -> #include "qsystemtrayicon.h"
i am using QT Creator 4.7.4. And i building for Symbian Belle

What should i do ?
(sorry for bad English)

amleto
1st July 2012, 00:40
1) mainwondow.h and mainwindow.cpp not in this example http://www.trinitydesktop.org/docs/qt4/desktop-systray.html
2) Qt include should look like #include <QSystemTrayIcon> not #include "QSystemTrayIcon.h"
3) show your code.

SNZ
2nd July 2012, 17:56
I can't understand what mean "mainwondow.h and mainwindow.cpp not in this example". i have only 1 header and 2 sources. Header is MainWindow.h
sources are mainwindow.cpp and main.cpp. i am creating a Mobile Qt Application.

My Code is:

QSystemTrayIcon *tray =new QSystemTrayIcon;
tray->setIcon(QIcon("emailRead.png"));
tray->show();

i included #include <QSystemTrayIcon> in Mainwindow.h also mainwindow.cpp. This code is working on simulator. But when i compile with symbian device give error "error: expected type-specifier before 'QSystemTrayIcon'" blinking on my code.

Thanx For Reply

amleto
2nd July 2012, 20:22
you said:
when i use QSystemTrayIcon example on Simulator"

What example? Since you are making everyone guess what you are talking about by
1) NOT showing any code
2) NOT giving any links to the code you are talking about
I made best effort guess that you were talking about the first example I found by googling.

Does symbian even have a tray/icon?

read my sig - give COMPLETE compilable code!

SNZ
2nd July 2012, 20:49
I am using QT Creator 4.7.4, QtSDK 1.2, i am creating an application for N8 with Symbian Belle SDK. I have an icon in my resources named "emailRead.png". My Code Template;


MainWindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QtCore/QCoreApplication>
#include <QSystemTrayIcon>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
QSystemTrayIcon *tray = new QSystemTrayIcon(this);
tray->setIcon(QPixmap(":/emailRead.png"));
tray->show();

}

MainWindow::~MainWindow()
{
delete ui;
}

void MainWindow::setOrientation(ScreenOrientation orientation)
{
#if defined(Q_OS_SYMBIAN)
// If the version of Qt on the device is < 4.7.2, that attribute won't work
if (orientation != ScreenOrientationAuto) {
const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char(' .'));
if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
return;
}
}
#endif // Q_OS_SYMBIAN

Qt::WidgetAttribute attribute;
switch (orientation) {
#if QT_VERSION < 0x040702
// Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
case ScreenOrientationLockPortrait:
attribute = static_cast<Qt::WidgetAttribute>(128);
break;
case ScreenOrientationLockLandscape:
attribute = static_cast<Qt::WidgetAttribute>(129);
break;
default:
case ScreenOrientationAuto:
attribute = static_cast<Qt::WidgetAttribute>(130);
break;
#else // QT_VERSION < 0x040702
case ScreenOrientationLockPortrait:
attribute = Qt::WA_LockPortraitOrientation;
break;
case ScreenOrientationLockLandscape:
attribute = Qt::WA_LockLandscapeOrientation;
break;
default:
case ScreenOrientationAuto:
attribute = Qt::WA_AutoOrientation;
break;
#endif // QT_VERSION < 0x040702
};
setAttribute(attribute, true);
}

void MainWindow::showExpanded()
{
#if defined(Q_OS_SYMBIAN) || defined(Q_WS_SIMULATOR)
showMaximized();
#elif defined(Q_WS_MAEMO_5)
showMaximized();
#else
show();
#endif
}




mainwindow.h


#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QSystemTrayIcon>
#include <QtGui/QMainWindow>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
Q_OBJECT
public:
enum ScreenOrientation {
ScreenOrientationLockPortrait,
ScreenOrientationLockLandscape,
ScreenOrientationAuto
};

explicit MainWindow(QWidget *parent = 0);
virtual ~MainWindow();

// Note that this will only have an effect on Symbian and Fremantle.
void setOrientation(ScreenOrientation orientation);

void showExpanded();

private:
Ui::MainWindow *ui;
};

#endif // MAINWINDOW_H





main.cpp


#include "mainwindow.h"

#include <QtGui/QApplication>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

MainWindow mainWindow;
mainWindow.setOrientation(MainWindow::ScreenOrient ationAuto);
mainWindow.showExpanded();

return app.exec();
}





.pro



# Add files and directories to ship with the application
# by adapting the examples below.
# file1.source = myfile
# dir1.source = mydir
DEPLOYMENTFOLDERS = # file1 dir1

symbian:TARGET.UID3 = 0xE0D24294

# Smart Installer package's UID
# This UID is from the protected range
# and therefore the package will fail to install if self-signed
# By default qmake uses the unprotected range value if unprotected UID is defined for the application
# and 0x2002CCCF value if protected UID is given to the application
#symbian:DEPLOYMENT.installer_header = 0x2002CCCF

# Allow network access on Symbian
#symbian:TARGET.CAPABILITY += NetworkServices

# If your application uses the Qt Mobility libraries, uncomment
# the following lines and add the respective components to the
# MOBILITY variable.
# CONFIG += mobility
# MOBILITY +=

SOURCES += main.cpp mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui

# Please do not modify the following two lines. Required for deployment.
include(deployment.pri)
qtcAddDeployment()