无法从 void 函数访问 Qt UI
Can't access Qt ui from void function
My mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
void test();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
我的mainwindow.cpp文件
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
void MainWindow::test()
{
ui->textBrowser->append("Hello world");
}
QT设计器说"ui没有在这个范围内声明",但我在同一个cpp文件中使用它。
编辑*增加mainwindow.h获取更多信息
test()
必须是类MainWindow
的成员方法:
void MainWindow::test()
{
ui->textBrowser->append("Hello world");
}
还必须添加mainwindow.h:
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
void test(); //<<
// ...
};
相关文章:
- Qt:从另一个窗口访问公共对象
- 如何访问QT中传递给程序的参数
- 从 QT Widget 对象实例访问 QT Widget 子成员
- 如何访问Qt::D isplayRole并在TableView中指定列
- 访问QT上的本地用户文件进行Web组件
- 使用C 访问QT / QML对象
- 在连接语句中访问Qt信号的"有效载荷"
- 访问QT小部件线程安全
- 无法从外部cpp文件访问Qt UI
- 如何访问Qt中父选项卡的属性
- QtWebkit javascript bridge,无法访问 Qt 对象方法
- 如何从任何类全局访问 QT 对话框
- 如何在c++项目中访问Qt的资源文件?
- 如何从非Qt函数访问Qt资源数据
- 从Webkit IFRAME(本地页面)访问Qt QWebView桥的技巧
- 使用QJSEngine从JavaScript访问Qt API
- 无法从 void 函数访问 Qt UI
- 访问Qt Designer创建的QWizardPage
- 如何访问Qt中另一个类的变量
- 无法使用 QtWebkit 通过 javascript 访问 Qt 对象方法