菜鸟求助一个简单的问题
添加一个菜单和一个图标的程序,现在问题有两个:
1. QStatusBar *statusBar = statusBar() ;
statusBar->addAction(openAction);
这两行代码有问题,error:C2064:项不会计算为接受0个参数的函数;
2. openAction = new QAction(QIcon(":/images/doc-open"), tr("&Open..."),
this);这行编译没问题,但是图片显示不出来。手动添加了资源文件,文件是这样的:
<RCC>
<qresource prefix="/images">
<file alias="doc-open">document-open.png</file>
</qresource>
</RCC>
哪位大侠帮忙看一下,代码附在下面。
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
setWindowTitle(tr("Main Window"));
openAction = new QAction(QIcon(":/images/doc-open"), tr("&Open..."),
this);
openAction->setShortcuts(QKeySequence::Open);
openAction->setStatusTip(tr("Open an existing file"));
connect(openAction, &QAction::triggered, this, &MainWindow::open);
QMenu *file = menuBar()->addMenu(tr("&File"));
file->addAction(openAction);
QToolBar *toolBar = addToolBar(tr("&File"));
toolBar->addAction(openAction);
QStatusBar *statusBar = statusBar() ;
statusBar->addAction(openAction);
}
MainWindow::~MainWindow()
{
}
void MainWindow::open()
{
QMessageBox::information(this, tr("Information"), tr("Open"));
}
[解决办法]
1.你定义statusBar换个名字吧。。。
2.openAction = new QAction(QIcon(":/images/doc-open.png"), tr("&Open...");
[解决办法]
关于QAction的使用可以看看这两篇文章,如果还有啥问题可留言!
http://blog.csdn.net/chenlong12580/article/details/8847236
http://blog.csdn.net/chenlong12580/article/details/8872035
[解决办法]