#include mainwindowh#include ui_mainwindowhWNDPROC lpPrevWndFunc = nullptr;LONGLONG intervalMose=0;上一次鼠标时间LONGLONG intervalKeyboard=0;上一次键盘时间MainWindow pThis;UI指针bool isRecall=false;是否回放中bool isRec=fa
这个错误提示是因为在类的静态成员函数 func_Message 中使用 pThis->ui->led_time->text() 访问了非静态成员 ui,而静态成员函数中无法直接访问非静态成员。解决方法是将 ui 成员变量改为静态,或者将 func_Message 函数改为非静态。建议将 ui 成员变量改为静态,因为在访问 ui 时需要使用类的对象指针,而静态成员变量可以直接使用类名访问,更加方便。具体实现方法如下:
在类的头文件中将 ui 成员变量声明为静态:
private:
static Ui::MainWindow *ui;
在类的源文件中对 ui 进行定义,并且在构造函数中对其进行初始化:
Ui::MainWindow *MainWindow::ui = new Ui::MainWindow;
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
ui->setupUi(this);
// ...
}
在 func_Message 函数中访问 ui 时使用类名即可:
runTime = QString::toInt(MainWindow::ui->led_time->text());
``
原文地址: https://www.cveoy.top/t/topic/ciYJ 著作权归作者所有。请勿转载和采集!