Qt 自定义槽

xiaoxiao2021-02-28  80

转载地址:http://zero66.blog.51cto.com/2729872/920758/

增加一个自定义的槽函数,用来改变QDlabel的内容.

改后的hello.h

 

#ifndef _HELLO_H_ #define _HELLO_H_ #include<QtGui/QtGui> #include<QDialog> class hello:public QDialog     Q_OBJECT public:     hello(QWidget* =0);     QLabel* label; public slots:     void myslot(); }; #endif 

改后的hello.cpp

 

#include"hello.h" #include<QtCore/QTextCodec> hello::hello(QWidget* parent):QDialog(parent)     QPushButton* closeBtn = new QPushButton(tr("关闭"));     QPushButton* changeBtn = new QPushButton(tr("请点击一下测试"));     label = new QLabel(tr("wait for test!"));     label->setFont(QFont("ubuntu",35,QFont::Bold));     QVBoxLayout* dlgLayoutnew QVBoxLayout;     dlgLayout->addWidget(label);     dlgLayout->addWidget(changeBtn);     dlgLayout->addWidget(closeBtn);     connect(closeBtn,SIGNAL(clicked()),this,SLOT(close()));     connect(changeBtn,SIGNAL(clicked()),this,SLOT(myslot()));     setLayout(dlgLayout); void hello::myslot()     label->setText(tr("hello,qt!")); 

 

 

转载请注明原文地址: https://www.6miu.com/read-53235.html

最新回复(0)