如果你能编译通过,那说明你在头文件中一定有这样的定义:
QLabel *test;
否则test_button_clicked()中会报错, test不存在
而你在构造函数中又这样定义:
QLabel *test = new QLabel();
其实质是新建了一个QLable,并不是头文件中声明的test,头文件中的 test并没有初始化,还是空值,所以在调用槽函数test_button_clicked()因为test为空,导致程序崩溃
解决办法:
把构造函数中的
QLabel *test = new QLabel();
改为:
test = new QLabel();
这也应该是你的本意