[問題] qt tray icon 問題
開發平台(Platform): (Ex: Win10, Linux, ...)
vs2015
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
qt5.7
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
目前寫的程式 在編譯時 經常會在小圖示的地方
出現很多我的程式的 tray icon
==================================================================
這邊是拿teamViewer的小圖示來做比喻(因為消失的速度太快來不及截圖)
http://imgur.com/gSuzM8U
大概會是這種長相
==================================================================
但只要打開小圖示的地方之後 就會自己自動清掉
不知道這是怎樣的原因造成的呢
以下是我的程式碼
QIcon icon = QIcon("IMAGE/logo.ico");
setWindowIcon(icon);
trayIcon = new QSystemTrayIcon(this);
trayIcon->setIcon(icon);
trayIcon->setToolTip("my app");
trayIcon->show();
//工具列圖示設定
trayIconMenu = new QMenu(this);
restoreAction = new QAction("執行app設置", this);
connect(restoreAction, SIGNAL(triggered()), this, SLOT(showNormal()));
quitAction = new QAction("退出", this);
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));//關閉app,qApp對
應的是程序全局唯一指針
trayIconMenu->addAction(restoreAction);
trayIconMenu->addSeparator();
trayIconMenu->addAction(quitAction);
trayIcon->setContextMenu(trayIconMenu);
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.160.80.105
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1484356898.A.C39.html
推
01/14 10:36, , 1F
01/14 10:36, 1F
→
01/14 12:23, , 2F
01/14 12:23, 2F
→
01/14 12:25, , 3F
01/14 12:25, 3F
推
01/14 18:30, , 4F
01/14 18:30, 4F
→
01/14 18:30, , 5F
01/14 18:30, 5F
→
01/14 18:30, , 6F
01/14 18:30, 6F
請問一下要怎樣看
我的寫法是這樣
但我寫this的話 我的parent就會是QMainWindow吧?
應該就是程式被關掉的時候(在工具列關掉)就要跟著被關掉了吧
#include "widgettest.h"
#include <QDebug>
widgetTEST::widgetTEST(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
trayIconMenu = new QMenu(this);
restoreAction = new QAction("執行app設置", this);
connect(restoreAction, SIGNAL(triggered()), this, SLOT(showNormal()));
quitAction = new QAction("退出", this);
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));//關閉app,qApp對
應的是程序全局唯一指針
trayIconMenu->addAction(restoreAction);
trayIconMenu->addSeparator();
trayIconMenu->addAction(quitAction);
trayIcon->setContextMenu(trayIconMenu);
}
※ 編輯: MOONY135 (1.160.80.105), 01/14/2017 19:47:39
推
01/15 03:05, , 7F
01/15 03:05, 7F
→
01/15 03:05, , 8F
01/15 03:05, 8F
→
01/15 03:05, , 9F
01/15 03:05, 9F
→
01/15 03:06, , 10F
01/15 03:06, 10F
→
01/15 03:06, , 11F
01/15 03:06, 11F
http://imgur.com/a/2cCP8 這是專案的位置
不知道您說的是在哪個資料夾裡?
這邊的意思應該是叫我去看VS ADD-IN自己生出來的ui.widgetTest.h檔對嗎?
/********************************************************************************
** Form generated from reading UI file 'widgettest.ui'
**
** Created by: Qt User Interface Compiler version 5.7.0
**
** WARNING! All changes made in this file will be lost when recompiling UI
file!
********************************************************************************/
#ifndef UI_WIDGETTEST_H
#define UI_WIDGETTEST_H
#include <QtCore/QVariant>
#include <QtWidgets/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QButtonGroup>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QMainWindow>
#include <QtWidgets/QMenuBar>
#include <QtWidgets/QStatusBar>
#include <QtWidgets/QToolBar>
#include <QtWidgets/QWidget>
QT_BEGIN_NAMESPACE
class Ui_widgetTESTClass
{
public:
QMenuBar *menuBar;
QToolBar *mainToolBar;
QWidget *centralWidget;
QStatusBar *statusBar;
void setupUi(QMainWindow *widgetTESTClass)
{
if (widgetTESTClass->objectName().isEmpty())
widgetTESTClass->setObjectName(QStringLiteral("widgetTESTClass"));
widgetTESTClass->resize(600, 400);
menuBar = new QMenuBar(widgetTESTClass);
menuBar->setObjectName(QStringLiteral("menuBar"));
widgetTESTClass->setMenuBar(menuBar);
mainToolBar = new QToolBar(widgetTESTClass);
mainToolBar->setObjectName(QStringLiteral("mainToolBar"));
widgetTESTClass->addToolBar(mainToolBar);
centralWidget = new QWidget(widgetTESTClass);
centralWidget->setObjectName(QStringLiteral("centralWidget"));
widgetTESTClass->setCentralWidget(centralWidget);
statusBar = new QStatusBar(widgetTESTClass);
statusBar->setObjectName(QStringLiteral("statusBar"));
widgetTESTClass->setStatusBar(statusBar);
retranslateUi(widgetTESTClass);
QMetaObject::connectSlotsByName(widgetTESTClass);
} // setupUi
void retranslateUi(QMainWindow *widgetTESTClass)
{
widgetTESTClass->setWindowTitle(QApplication::translate("widgetTESTClass",
"widgetTEST", 0));
} // retranslateUi
};
namespace Ui {
class widgetTESTClass: public Ui_widgetTESTClass {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_WIDGETTEST_H
※ 編輯: MOONY135 (1.160.80.105), 01/15/2017 12:35:42
推
01/15 15:52, , 12F
01/15 15:52, 12F
→
01/15 15:53, , 13F
01/15 15:53, 13F
→
01/15 19:57, , 14F
01/15 19:57, 14F
/****************************************************************************
** Meta object code from reading C++ file 'widgettest.h'
**
** Created by: The Qt Meta Object Compiler version 67 (Qt 5.7.0)
**
** WARNING! All changes made in this file will be lost!
*****************************************************************************/
#include "../../widgettest.h"
#include <QtCore/qbytearray.h>
#include <QtCore/qmetatype.h>
#if !defined(Q_MOC_OUTPUT_REVISION)
#error "The header file 'widgettest.h' doesn't include <QObject>."
#elif Q_MOC_OUTPUT_REVISION != 67
#error "This file was generated using the moc from 5.7.0. It"
#error "cannot be used with the include files from this version of Qt."
#error "(The moc has changed too much.)"
#endif
QT_BEGIN_MOC_NAMESPACE
struct qt_meta_stringdata_widgetTEST_t {
QByteArrayData data[1];
char stringdata0[11];
};
#define QT_MOC_LITERAL(idx, ofs, len) \
Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \
qptrdiff(offsetof(qt_meta_stringdata_widgetTEST_t, stringdata0) + ofs \
- idx * sizeof(QByteArrayData)) \
)
static const qt_meta_stringdata_widgetTEST_t qt_meta_stringdata_widgetTEST = {
{
QT_MOC_LITERAL(0, 0, 10) // "widgetTEST"
},
"widgetTEST"
};
#undef QT_MOC_LITERAL
static const uint qt_meta_data_widgetTEST[] = {
// content:
7, // revision
0, // classname
0, 0, // classinfo
0, 0, // methods
0, 0, // properties
0, 0, // enums/sets
0, 0, // constructors
0, // flags
0, // signalCount
0 // eod
};
void widgetTEST::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int
_id, void **_a)
{
Q_UNUSED(_o);
Q_UNUSED(_id);
Q_UNUSED(_c);
Q_UNUSED(_a);
}
const QMetaObject widgetTEST::staticMetaObject = {
{ &QMainWindow::staticMetaObject, qt_meta_stringdata_widgetTEST.data,
qt_meta_data_widgetTEST, qt_static_metacall, Q_NULLPTR, Q_NULLPTR}
};
const QMetaObject *widgetTEST::metaObject() const
{
return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() :
&staticMetaObject;
}
void *widgetTEST::qt_metacast(const char *_clname)
{
if (!_clname) return Q_NULLPTR;
if (!strcmp(_clname, qt_meta_stringdata_widgetTEST.stringdata0))
return static_cast<void*>(const_cast< widgetTEST*>(this));
return QMainWindow::qt_metacast(_clname);
}
int widgetTEST::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
_id = QMainWindow::qt_metacall(_c, _id, _a);
if (_id < 0)
return _id;
return _id;
}
QT_END_MOC_NAMESPACE
※ 編輯: MOONY135 (1.160.80.105), 01/15/2017 20:00:32
推
01/15 20:30, , 15F
01/15 20:30, 15F
→
01/15 20:30, , 16F
01/15 20:30, 16F
→
01/15 20:30, , 17F
01/15 20:30, 17F
→
01/15 20:32, , 18F
01/15 20:32, 18F
→
01/15 20:32, , 19F
01/15 20:32, 19F
→
01/15 20:33, , 20F
01/15 20:33, 20F
→
01/15 20:33, , 21F
01/15 20:33, 21F
→
01/15 20:35, , 22F
01/15 20:35, 22F
→
01/15 20:35, , 23F
01/15 20:35, 23F
→
01/15 20:36, , 24F
01/15 20:36, 24F
→
01/15 20:36, , 25F
01/15 20:36, 25F
→
01/16 09:35, , 26F
01/16 09:35, 26F
→
01/16 14:01, , 27F
01/16 14:01, 27F
→
01/16 14:02, , 28F
01/16 14:02, 28F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):