void nozologia::menu(){ int i = 0; QMenu *contextMenu = new QMenu; contextMenu->addAction("Ввод рецепта"); contextMenu->addAction("РР-1 Отчет"); contextMenu->addAction("РЛ-1 Отчет"); contextMenu->addSeparator(); contextMenu->addAction("Выход"); contextMenu->addSeparator(); contextMenu->setGeometry(QCursor::pos().x(),QCursor::pos().y(),contextMenu->sizeHint().width(),contextMenu->sizeHint().height()); contextMenu->show(); connect(contextMenu,SIGNAL(triggered(QAction*)),this,SLOT(exit(QAction*))); connect(contextMenu,SIGNAL(triggered(QAction*)),this,SLOT(vvod(QAction*))); connect(contextMenu,SIGNAL(triggered(QAction*)),this,SLOT(pp1(QAction*))); connect(contextMenu,SIGNAL(triggered(QAction*)),this,SLOT(pl1(QAction*))); while (i != QApplication::topLevelWidgets().count()) { if (QApplication::topLevelWidgets().value(i)->windowTitle() != "" && QApplication::topLevelWidgets().value(i)->windowTitle() != "7 Нозологий" && QApplication::topLevelWidgets().value(i)->isVisible()) { contextMenu->addAction(QApplication::topLevelWidgets().value(i)->windowTitle()); } i++; }}
C++ (Qt) QMenu menu; foreach (QWidget *w, QApplication::topLevelWidgets()) { menu.addAction(w.windowTitle(), this, SLOT(showWidget())).setData(w); } menu.exec();
C++ (Qt) QAction *action = static_const<QAction*> (sender); if (action) { QWidget *w= static_const<QWidget*>(action->data().toInt()); if (w) w->show(); }
void nozologia::menu(){ int i = 0; QMenu *contextMenu = new QMenu; contextMenu->addAction("Ввод рецепта"); contextMenu->addAction("РР-1 Отчет"); contextMenu->addAction("РЛ-1 Отчет"); contextMenu->addSeparator(); contextMenu->addAction("Выход"); contextMenu->addSeparator(); contextMenu->setGeometry(QCursor::pos().x(),QCursor::pos().y(),contextMenu->sizeHint().width(),contextMenu->sizeHint().height()); contextMenu->show(); connect(contextMenu,SIGNAL(triggered(QAction*)),this,SLOT(exit(QAction*))); connect(contextMenu,SIGNAL(triggered(QAction*)),this,SLOT(vvod(QAction*))); connect(contextMenu,SIGNAL(triggered(QAction*)),this,SLOT(pp1(QAction*))); connect(contextMenu,SIGNAL(triggered(QAction*)),this,SLOT(pl1(QAction*))); foreach (QWidget *m, QApplication::topLevelWidgets()) { if (m->windowTitle() != "" && m->windowTitle() != "7 Нозологий" && m->isVisible()) { contextMenu->addAction(m->windowTitle(), this, SLOT(showWidget()))->setData(m); } } contextMenu->exec();}
void nozologia::showWidget(QString *act){ QAction *action = static_cast<QAction*>(sender); if (action) { QWidget *m= static_cast<QWidget*>(action->data().toInt()); if (m) m->show(); }}
'QVariant::QVariant(void*)' is privatewithin this contextinvalid static_cast from type '<unresolved overloaded function type>' to type 'QAction*'nvalid static_cast from type 'int' to type 'QWidget*'
void nozologia::menu(){ int i = 0; QMenu *contextMenu = new QMenu; contextMenu->addAction("Ввод рецепта"); contextMenu->addAction("РР-1 Отчет"); contextMenu->addAction("РЛ-1 Отчет"); contextMenu->addSeparator(); contextMenu->addAction("Выход"); contextMenu->addSeparator(); contextMenu->setGeometry(QCursor::pos().x(),QCursor::pos().y(),contextMenu->sizeHint().width(),contextMenu->sizeHint().height()); contextMenu->show(); connect(contextMenu,SIGNAL(triggered(QAction*)),this,SLOT(exit(QAction*))); connect(contextMenu,SIGNAL(triggered(QAction*)),this,SLOT(vvod(QAction*))); connect(contextMenu,SIGNAL(triggered(QAction*)),this,SLOT(pp1(QAction*))); connect(contextMenu,SIGNAL(triggered(QAction*)),this,SLOT(pl1(QAction*))); foreach (QWidget *m, QApplication::topLevelWidgets()) { if (m->windowTitle() != "" && m->windowTitle() != "7 Нозологий" && m->isVisible()) { contextMenu->addAction(m->windowTitle(), this,SLOT(showWidget()))->setData(m->windowTitle()); } } contextMenu->exec();}void nozologia::showWidget(){ QAction *action = (QAction*)sender(); if (action) { QWidget *m = (QWidget*)action->data().toInt(); if (m) m->show(); }}
C++ (Qt) if (m) { m->show(); m->activeWindow(); }
void nozologia::showWidget(){ QAction *action = (QAction*)sender(); qDebug() << action->text(); qDebug() << action->objectName(); qDebug() << action; if (action) { QWidget *m = (QWidget*)action->data().toInt(); qDebug() << m; if (m) { m->setWindowFlags(m->windowFlags() | Qt::WindowStaysOnTopHint); m->raise(); m->show(); m->activateWindow(); } }}
"Отчет РЛ-1" "" QAction(0x1072c2c8) QObject(0x0)
C++ (Qt) QWidget *m = (QWidget*)action->data().toInt(); qDebug() << m;