QML的使用

生成qml工程,主入口为:main.cpp

//main.cpp
#include <QGuiApplication>
#include <QQmlApplicationEngine>

int main(int argc char *argv[])
{
	QCoreApplication app(argc,argv);
	QQmlApplicationEngin engin;
	const QUrl url(QStringLiteral("qrc:/main.qml"));
	QObject::connect(&engin, &QQmlApplicationEngin::objectCreated, &app, [url](QObject *obj, const QUrl &objUrl){
		if(!obj && url == objUrl)
			QCoreApplication::exit(-1);
	},Qt::QueuedConnection);

	return app.exec();
}
//main.qml
//每行可用;也可不用;   “on+信号”槽函数
//===类型值判断  ==只判断值
import QtQuick 2.12
import QtQuick.Controls 2.5

ApplicationWindow{
	id:window
	visible:true
	width:640
	height:480
	title:qsTr("Tabs")
	property int name: 1  //变量
	fuction aaa() {
		//consol.log("123");
		consol.log(name);
	}

	Button{
		id:button1
		x:200
		y:200
		text:qsTr("Test")
		icon.source: "qrc:/icon/up.png"
		onClicked:{
			console.log("1234");			
		}
		onDoubleClicked: aaa()
	}
}
上一篇:java的优点和误解 《java核心技术卷i》第一章


下一篇:使用ML.NET实现基于RFM模型的客户价值分析