在运行时尝试更改QPushButton文本时,我做错了什么
What am I doing wrong trying to change QPushButton text at runtime?
我对使用QTCreator和Linux图形开发进行编码是个新手。我在这里做错了什么,可能是微不足道的事?
我可以在不使用form方法的情况下编写这些代码并使其轻松工作,但我真的更喜欢使用图形界面,因为它应该更快(一旦我知道编译器希望我做什么(。
当我输入这个代码时,它告诉我btnStopGo没有在这个上下文中定义。我使用表单界面将按钮放到表单上。
代码在文件mainwindow.cpp 中
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
...
void MainWindow::on_btnStopGo_clicked()
{
if (bDoStream){
if (bStreaming){
//TODO: Send stop stream signal, save stream to file, dispose stream
bStreaming = false;
btnStopGo->setText("Go");
}
else{
btnStopGo->setText("Stop");
bStreaming = true;
// TODO: request a stream of quotes
}
}
else {
// TODO: Get a single quote tick
}
}
主窗口.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT;
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
...
private slots:
...
void on_btnSelect_clicked();
void on_btnStopGo_clicked();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
项目中的其他可见文件有:Hello2.pro、main.cpp和mainwindow.ui.main.cpp声明mywindow为访问主窗口的变量。我试过用";ui.btnStopGo";,mywindow.btnStopGo,用户界面->btnStopGo(炸毁编译器(,以及我能想到的所有其他组合。到目前为止,它们都不起作用。
我不知道这是否相关,但我正在使用:Qt创建者4.11.0基于Qt 5.12.8(GCC 9.3.0,64位(在Linux Mint 20 Cinnamon上手动添加KDE。
如果将按钮放在表单设计器中,并调用按钮btnStopGo
,则它最终会编译为ui_mainwindow.h
和.cc
文件。您自己编写的MainWindow
类没有名为btnStopGo
的(成员(变量。它有一个变量ui
,指向表单设计器生成的用户界面。
请改用ui->btnStopGo->setText("stop")
。
相关文章:
- #定义c-预处理器常量..我做错了什么
- 努力将整数转换为链表。不知道我在这里做错了什么
- .h 和.cpp文件分离时出错,但仅使用 .h 文件时没有错误.我做错了什么?
- 我的C++线程做错了什么?
- 谁能告诉我我用 getline 做错了什么 (cpp) 格式
- 没有输出的合并排序我做错了什么?
- 我正在尝试使用 while 循环从字符串中删除字母,直到没有字母。我在这里做错了什么?
- 在C++中使用 AKS 素数测试计算双胞胎素数 我做错了什么?
- 我一直试图弄清楚我在这个链表程序中做错了什么
- 我正在尝试学习如何在 c++ 中传递指针,但出现错误:没有用于调用"test"的匹配函数。我做错了什么?
- FFMPEG,C++,内存泄漏,我做错了什么?
- 我做错了什么?反向字符串 C++
- 我在这个课上做错了什么?
- 创建整数的 2D 数组,该数组将使用两个函数用随机数填充矩阵.我做错了什么?
- 在不使用内置库函数的情况下添加字符串,我做错了什么?
- 我做错了什么?GetDiskFreeSpaceExA的功能根本不起作用
- 我在查找和字符串上做错了什么?
- 我正在尝试用 c++ 制作一个日志记录框架,但信息没有传递给记录器的子组件,我做错了什么?
- 我在尝试将多个值push_back向量时出错。我做错了什么?
- 插入排序:我做错了什么?