我收到错误消息:



在此功能中,有什么想法吗?

void TextEditor::createMenu(){
    menu = new QMenu(tr("&TextEditor"), this);
    QMainWindow::menuBar()->addMenu(menu);
    menu->addAction(tr("&Bold"), this, SLOT(setBold()), tr("Alt+B"));
    menu->addAction(tr("&Underline"), this, SLOT(setUnderline()), tr("ALT+U"));
    menu->addAction(tr("&Italics"), this, SLOT(setItalics()), tr("Alt+I"));
}

最佳答案

问题在这里:

QMainWindow::menuBar()->addMenu(menu);
^^^^^^^^^^^^^

方法menuBar()不是静态方法,没有对象就无法调用它。您必须从一个对象调用它:
main_window_object->menuBar()->addMenu(menu);
... or ...
this->menuBar()->addMenu(menu);

关于c++ - 尝试在Qt中创建菜单时出现错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16063383/

10-12 00:33
查看更多