对按钮事件执行功能
execute function on pushbutton event
这里完全是初学者。每当按下pushButton时,我都试图执行一个函数,但它只有在关闭主窗口后才能执行。我怎样才能在按下按钮时立即实现这一点?
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <iostream>
using namespace std;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
cout << "test";
}
"测试"仅在窗口关闭后打印。当我调用自己的函数时,也会发生同样的事情。
如果您只是调试/测试,并且您不打算让您的最终应用程序使用它,您可以尝试以下操作:
#include <QDebug>
void MainWindow::on_pushButton_clicked()
{
qDebug() << "test";
}
try:
void MainWindow::on_pushButton_clicked()
{
std::cout << "test" << std::endl;
}
通过提供endl;set:cout缓冲区被刷新,您也可以添加std::cout << std::flush;
以刷新缓冲区。
此外,请避免使用命名空间std;
相关文章:
- 在执行其他功能的同时播放动画(LED矩阵和Arduino/ESP8266)
- QML按钮点击功能执行顺序
- 如何用共享库替换可执行C++程序的功能?
- 当再次触发信号时,从Qt插槽执行的功能被第二次调用时会发生什么?
- 是否有一个Windows驱动程序函数可以执行Windows文件api SeFileAttributes的等效功能
- 如何使用C++在sqlite3数据库中执行写文件功能
- "no main"用于C++中链接或执行的功能
- 维护/维持两个代码集的风险,一个用于 CPU,一个用于 GPU,需要执行非常相似的功能
- 是否有用于执行反向字符串拆分器的开箱即用功能?
- 线程功能之一不执行可能的比赛条件
- C 程序如果功能中的语句不执行.在逻辑上似乎是错误的
- 无法从Linux,C ++执行"my_script" python脚本"main(filename)"功能;pModule = PyImport_Import(pName);返回空值
- 为什么要以相反的顺序执行RUST功能和FFI C 功能
- 如何与 PlaySound 同时执行其他功能?
- 在C 功能执行后,使用GCHANDLE CRALSES将大型结构从C#Unity脚本传递到C DLL
- 我正在尝试执行tranpose功能,但无法获得
- 有没有办法获得功能大小并分配内存以复制和执行
- 功能执行时间很奇怪
- 在Visual Studio Enterprise 2017(C )中测量功能执行时间
- QProgresDialog:忙碌的等待栏在功能执行时没有移动