尝试撤消重做时出错

时间:2014-12-11 05:59:58

标签: c++ qt

我正在尝试在多文档界面上执行撤消/重做但面临以下错误:

 no matching function for call to 'qobject_cast(QMdiSubWindow*&)'
       return qobject_cast<CadGraphicsView *>(activeSubWindow);

我的上述功能代码如下:

 MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
    {
        m_undoGroup = new QUndoGroup(this);
        QAction *undoAction = m_undoGroup->createUndoAction(this);
        undoAction->setShortcut(QKeySequence::Undo);
        QAction *redoAction = m_undoGroup->createRedoAction(this);
        redoAction->setShortcut(QKeySequence::Redo);
        menuEdit->insertAction(menuEdit->actions().at(0), undoAction);
        menuEdit->insertAction(undoAction, redoAction);
        menuEdit->addAction(undoAction);
        menuEdit->addAction(redoAction);
        updateActions();
    }
              void MainWindow::setCurrentDocument()
            {
               mdiArea->currentSubWindow();
            }

            void MainWindow::addnewFile()
            {
                m_undoGroup->addStack(view->scene->undoStack());
                connect(view->scene->undoStack(), SIGNAL(indexChanged(int)), this, SLOT(updateActions()));
                connect(view->scene->undoStack(), SIGNAL(cleanChanged(bool)), this, SLOT(updateActions()));
            }

            void MainWindow::updateActions()
            {
                CadGraphicsScene *scene = currentDocument();
                m_undoGroup->setActiveStack(scene == 0 ? 0 : scene->undoStack());
            }

         CadGraphicsView *MainWindow::currentDocument() const
         {
         if (QMdiSubWindow *activeSubWindow = mdiArea->currentSubWindow())
              return qobject_cast<CadGraphicsView *>(activeSubWindow);

            return 0;
        }

        void MainWindow::newFile()
        {
            // creates a new file
            createMdiView();

            view->newFile();
            addnewFile();
            curFileName = tr("Document %1").arg(++fileNumber);
            view->setWindowTitle(curFileName);
            view->scene->installEventFilter(this);
            view->show();

            isEntitySelected = false;
        }

        CadGraphicsView *MainWindow::createMdiView()
        {
            // creates a graphicsView and add it to the MDI window
            view = new CadGraphicsView;
            QMdiSubWindow *w = mdiArea->addSubWindow(view);
            mdiArea->setActiveSubWindow(w);
            windowViewList.append(qMakePair(w, view));

返回视图;         }

你能帮我解决一下这个错误。我已经添加了它的工作原理。

1 个答案:

答案 0 :(得分:0)

解决了我的问题。我需要更改currentDocument函数,如下所示:

CadGraphicsView *MainWindow::currentDocument() const
{
    return qobject_cast<CadGraphicsView *>(mdiArea->parentWidget());
}