int main(int argc, char* argv[])
{
TeSingleInstance instance("Service");
if (instance.isAnotherInstanceRunning())
return 0;
Q_INIT_RESOURCE(Service);
if (argc > 0)
{
info.setFile(argv[0]);
QDir::setCurrent(info.
canonicalPath());
}
MainWindow window;
return application.exec();
}
MainWindow
::MainWindow(QWidget *parent, Qt
::WFlags flags
){
mMainWindow.setupUi(this);
createActions();
createTrayIcon();
mSystemTray.icon->show();
// Do some connect to Ui events
}
void MainWindow::createActions()
{
mSystemTray.
minimizeAction = new QAction(tr
("Mi&nimize"),
this);
connect(mSystemTray.minimizeAction, SIGNAL(triggered()), this, SLOT(hide()));
mSystemTray.
maximizeAction = new QAction(tr
("Ma&ximize"),
this);
connect(mSystemTray.maximizeAction, SIGNAL(triggered()), this, SLOT(showMaximized()));
mSystemTray.
restoreAction = new QAction(tr
("&Restore"),
this);
connect(mSystemTray.restoreAction, SIGNAL(triggered()), this, SLOT(showNormal()));
mSystemTray.
settingsAction = new QAction(tr
("&Settings"),
this);
connect(mSystemTray.settingsAction, SIGNAL(triggered()), this, SLOT(onSettingsActionTriggered()));
mSystemTray.
quitAction = new QAction(tr
("&Quit"),
this);
connect(mSystemTray.quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
}
void MainWindow::createTrayIcon()
{
mSystemTray.
menu = new QMenu(this);
mSystemTray.menu->addAction(mSystemTray.minimizeAction);
mSystemTray.menu->addAction(mSystemTray.maximizeAction);
mSystemTray.menu->addAction(mSystemTray.restoreAction);
mSystemTray.menu->addSeparator();
mSystemTray.menu->addAction(mSystemTray.settingsAction);
mSystemTray.menu->addSeparator();
mSystemTray.menu->addAction(mSystemTray.quitAction);
mIcon.addFile(":/myIcon.ico");
mSystemTray.icon->show();
mSystemTray.icon->setIcon(mIcon);
setWindowIcon(mIcon);
mSystemTray.icon->setContextMenu(mSystemTray.menu);
}
int main(int argc, char* argv[])
{
TeSingleInstance instance("Service");
if (instance.isAnotherInstanceRunning())
return 0;
Q_INIT_RESOURCE(Service);
if (argc > 0)
{
QFileInfo info;
info.setFile(argv[0]);
QDir::setCurrent(info.canonicalPath());
}
QApplication application(argc, argv);
MainWindow window;
return application.exec();
}
MainWindow::MainWindow(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
QCoreApplication::setOrganizationName("Tetraedge Games");
QCoreApplication::setOrganizationDomain("tetraedge.com");
QCoreApplication::setApplicationName("Service");
QApplication::setQuitOnLastWindowClosed(false);
QSettings::setDefaultFormat(QSettings::IniFormat);
mMainWindow.setupUi(this);
createActions();
createTrayIcon();
mSystemTray.icon->show();
// Do some connect to Ui events
}
void MainWindow::createActions()
{
mSystemTray.minimizeAction = new QAction(tr("Mi&nimize"), this);
connect(mSystemTray.minimizeAction, SIGNAL(triggered()), this, SLOT(hide()));
mSystemTray.maximizeAction = new QAction(tr("Ma&ximize"), this);
connect(mSystemTray.maximizeAction, SIGNAL(triggered()), this, SLOT(showMaximized()));
mSystemTray.restoreAction = new QAction(tr("&Restore"), this);
connect(mSystemTray.restoreAction, SIGNAL(triggered()), this, SLOT(showNormal()));
mSystemTray.settingsAction = new QAction(tr("&Settings"), this);
connect(mSystemTray.settingsAction, SIGNAL(triggered()), this, SLOT(onSettingsActionTriggered()));
mSystemTray.quitAction = new QAction(tr("&Quit"), this);
connect(mSystemTray.quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
}
void MainWindow::createTrayIcon()
{
mSystemTray.menu = new QMenu(this);
mSystemTray.menu->addAction(mSystemTray.minimizeAction);
mSystemTray.menu->addAction(mSystemTray.maximizeAction);
mSystemTray.menu->addAction(mSystemTray.restoreAction);
mSystemTray.menu->addSeparator();
mSystemTray.menu->addAction(mSystemTray.settingsAction);
mSystemTray.menu->addSeparator();
mSystemTray.menu->addAction(mSystemTray.quitAction);
mIcon.addFile(":/myIcon.ico");
mSystemTray.icon = new QSystemTrayIcon(this);
mSystemTray.icon->show();
mSystemTray.icon->setIcon(mIcon);
setWindowIcon(mIcon);
mSystemTray.icon->setContextMenu(mSystemTray.menu);
}
To copy to clipboard, switch view to plain text mode
Bookmarks