如何在主函数中从SLOT调出showNormal?

时间:2015-02-03 08:43:44

标签: c++ qt

我有

QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
QObject* root = engine.rootObjects().at(0);

QAction *restoreAction = new QAction(QObject::tr("&Restore"), root);
root->connect(restoreAction, SIGNAL(triggered()), root, SLOT(showNormal()));

在主体中,它的工作原理。不过我想在那里打电话给showNormal,但不是在插槽中,我可以找到它的位置,它是如何工作的?

最后,我试图在点击托盘图标

上显示我的窗口
root->connect(trayIcon, &QSystemTrayIcon::activated,
              [root] (QSystemTrayIcon::ActivationReason reason) {
  switch (reason) {
  case QSystemTrayIcon::Trigger:
  case QSystemTrayIcon::DoubleClick:
    ((QWidget*)root)->showNormal();
到目前为止它还没有工作

1 个答案:

答案 0 :(得分:1)

您应该将root转换为QQuickWindow

QQuickWindow *root = qobject_cast<QQuickWindow *>(engine.rootObjects().at(0));
root->showNormal();