0
点赞
收藏
分享

微信扫一扫

Qt面向事件编程的第一个程序(hello world)


流程

第一步

在ui文件下使用Qt.Designer进行页面设计,在设计页面的时候要习惯使用layout机制,这样才能使界面整洁;

第二步

在类头文件中加入槽函数声明:

private slots:
	int onshowclicked(bool checked);

第三步

在cpp文件中加入槽函数定义以及connect函数连接槽函数和信号函数:

#include "QtGuiClass.h"
QtGuiClass::QtGuiClass(QWidget *parent)
	: QWidget(parent)
{
	ui.setupUi(this);
	connect(
		ui.ptnshow,
		SIGNAL(clicked(bool)),
		this,
		SLOT(onshowclicked(bool))
	);
}

QtGuiClass::~QtGuiClass()
{
}
int QtGuiClass::onshowclicked(bool checked)
{
	ui.plainTextEdit->setPlainText("Hello world");
	return 0;
}

第四步

在main函数中建立相关对象运行即可:

QtGuiClass w;
w.show();

结果

(点击show,即在文本框中显示hello world)

Qt面向事件编程的第一个程序(hello world)_main函数


举报

相关推荐

0 条评论