读书人

初学者一个简单的有关问题

发布时间: 2013-07-16 22:38:05 作者: rapoo

菜鸟求助一个简单的问题
添加一个菜单和一个图标的程序,现在问题有两个:

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
[解决办法]

引用:
添加一个菜单和一个图标的程序,现在问题有两个:

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"));


我感觉你的资源文件、程序没什么问题,你可以看看document-open.png这个图片的位置,是不是在当前目录下!

读书人网 >QT开发

热点推荐