为什么会出现这个错误:引用‘statusBar’暧昧..来了?这是一个错误吗?
我使用 QT Designer 创建了一个 QMainWindow。 我们知道,它默认有statusBar。
默认情况下,QT Designer 将其对象名称指定为“statusBar”。 现在,当我尝试调用:-
statusBar()->showMessage(tr("File successfully loaded."), 3000);
因为我们有一个带有原型的函数: QStatusBar * QMainWindow::statusBar () const
编译器显示错误:-
错误:对“statusBar”的引用不明确。
错误:候选者是:QStatusBar* Ui_MainWindow::statusBar
错误:QStatusBar*QMainWindow::statusBar() const
实际上,我正在阅读一本书“DANIEL MOLKENTIN 构建Qt 应用程序的艺术”。我正在编译书中给出的相同代码。
上面的代码位于 mainwindows.cpp 中,我已包含“mainwindow.h”和“mainwindows.cpp”。其中“ui_mainwindow.h”...
这是QT4中的错误吗?
I created a QMainWindow using QT Designer.
As we know, it has statusBar by default.
By default, QT Designer gave its objectname as "statusBar".
Now, when I tried to call like:-
statusBar()->showMessage(tr("File successfully loaded."), 3000);
as we have a function with prototype: QStatusBar * QMainWindow::statusBar () const
The Compiler shows the error:-
error: reference to ‘statusBar’ is ambiguous.
error: candidates are: QStatusBar* Ui_MainWindow::statusBar
error: QStatusBar*QMainWindow::statusBar() const
Actually, i was following a book "The Art of Building Qt Applications by DANIEL MOLKENTIN". And I am compiling the same code given in book.
Above code is in mainwindows.cpp and i have included "mainwindow.h" & "ui_mainwindow.h" in it...
Is this a bug in QT4??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请求 statusBar() 方法的特定版本:
Ask for a specific version of the method statusBar():
问题是 QMainWindow 扩展了 Ui_MainWindow,它也定义了 statusBar 方法。
以前版本的 QT 中可能不是这种情况。
The problem is that QMainWindow extends Ui_MainWindow, which also defines the statusBar method.
Probably this wasn't the case in previous versions of QT.
我也读过那本书,也遇到了同样的问题。决定是:
调用方法
QMainWindow::statusBar()
QMainWindow::statusBar()->showMessage(tr("文件已成功加载。"), 3000);
或使用指针
*statusBar
来自Ui_MainWindow
Ui_MainWindow::statusBar->showMessage(tr("文件已成功加载。"), 3000);
I also read that book and had the same problem. The decision is:
invoke the method
QMainWindow::statusBar()
QMainWindow::statusBar()->showMessage(tr("File successfully loaded."), 3000);
or use a pointer
*statusBar
fromUi_MainWindow
Ui_MainWindow::statusBar->showMessage(tr("File successfully loaded."), 3000);