Init
This commit is contained in:
291
07-Other/Qt/QtQuick/Qt:解决QtQuick(QML)程序,在虚拟机或者某些环境下,动画速度过快的问题.md
Normal file
291
07-Other/Qt/QtQuick/Qt:解决QtQuick(QML)程序,在虚拟机或者某些环境下,动画速度过快的问题.md
Normal file
@@ -0,0 +1,291 @@
|
||||
## 参考网址
|
||||
https://blog.csdn.net/wsj18808050/article/details/54234956
|
||||
|
||||
Qt:获取屏幕物理长度和宽度(CM)
|
||||
https://blog.csdn.net/wsj18808050/article/details/54345537
|
||||
|
||||
Qt:5.8新特新,QtLite使用方法,以及缩减应用体积的效果
|
||||
https://blog.csdn.net/wsj18808050/article/details/55808104
|
||||
|
||||
QML 中的屏幕适配问题
|
||||
https://blog.csdn.net/qyvlik/article/details/51241425
|
||||
|
||||
QT5(9)HTTP POST GET COOKIE 网络编程
|
||||
```c++
|
||||
#include <QNetworkCookie> //单个cookie
|
||||
#include <QNetworkCookieJar> //储存cookie
|
||||
```
|
||||
https://blog.csdn.net/qq_16234613/article/details/53783391
|
||||
|
||||
qt 获取部分的cookie信息 如何把获取的cookie转换为QString类型 正则表达式
|
||||
https://blog.csdn.net/qq_22403265/article/details/51333226
|
||||
|
||||
### cookiebrowser使用webview载入cookie
|
||||
```
|
||||
m_store = m_webview->page()->profile()->cookieStore();
|
||||
m_store->loadAllCookies();
|
||||
```
|
||||
|
||||
### QML Settings 小的示例
|
||||
Setting 可以存储一些变量就想配置文件一样
|
||||
https://www.cnblogs.com/hbrw/p/6744094.html
|
||||
|
||||
### 直接导入qml
|
||||
Importing QML Document Directories
|
||||
目录结构:
|
||||
```
|
||||
myapp
|
||||
|- mycomponents
|
||||
|- CheckBox.qml
|
||||
|- DialogBox.qml
|
||||
|- Slider.qml
|
||||
|- main
|
||||
|- application.qml
|
||||
```
|
||||
那么可以:
|
||||
```
|
||||
import "../mycomponents"
|
||||
|
||||
DialogBox {
|
||||
CheckBox {
|
||||
// ...
|
||||
}
|
||||
Slider {
|
||||
// ...
|
||||
}
|
||||
}
|
||||
```
|
||||
但是创建一个命名空间来导入会更好
|
||||
```
|
||||
import "../mycomponents" as MyComponents
|
||||
|
||||
MyComponents.DialogBox {
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
### qml文件间通讯
|
||||
3.题回正传,直接上代码(以StackView管理页面为例)
|
||||
(1)page1.qml跳转到page2.qml传值
|
||||
```
|
||||
page1.qml
|
||||
|
||||
Rectangle
|
||||
{
|
||||
id:rect1
|
||||
...
|
||||
MouseArea {
|
||||
id: maStartQuery
|
||||
anchors.fill: parent
|
||||
onClicked:
|
||||
{
|
||||
if(!stackView.busy)
|
||||
stackView.push(Qt.resolvedUrl("qrc:///qml/page2.qml"),
|
||||
{name:"张三"})//给page2.qml的name传值“张三”,name必须在page2.qml中定义成属性
|
||||
}
|
||||
}
|
||||
...
|
||||
}
|
||||
|
||||
page2.qml定义如下
|
||||
|
||||
Rectangle
|
||||
{
|
||||
id:rect2
|
||||
...
|
||||
property string name:""//要传的值
|
||||
...
|
||||
|
||||
}
|
||||
```
|
||||
(2)page2.qml点击"确定"按钮时将结果返回给page1.qml
|
||||
|
||||
A.在page1.qml中增加一个函数clickedfunc,当点击page2.qml中"确定"按钮时调用;
|
||||
B.在page2.qml中增加一个属性containerqml,用来记录page1.qml;
|
||||
C.在从page1.qml跳转到page2.qml时,将rect1传给page2.qml的containerqml属性。
|
||||
```
|
||||
page1.qml
|
||||
Rectangle
|
||||
{
|
||||
id:rect1
|
||||
...
|
||||
MouseArea {
|
||||
id: maStartQuery
|
||||
anchors.fill: parent
|
||||
onClicked:
|
||||
{
|
||||
if(!stackView.busy)
|
||||
stackView.push(Qt.resolvedUrl("qrc:///qml/page2.qml"),
|
||||
{name:"张三",containerqml:rect1})
|
||||
}
|
||||
}
|
||||
|
||||
//当点击page2.qml中"确定"按钮时调用
|
||||
function clickedfunc(temp)
|
||||
{
|
||||
console.log("改成了:"+temp);
|
||||
stackView.pop();//返回到本页
|
||||
}
|
||||
...
|
||||
}
|
||||
|
||||
page2.qml
|
||||
Rectangle
|
||||
{
|
||||
id:rect2
|
||||
...
|
||||
property variant containerqml: null
|
||||
property string name:""//要传的值
|
||||
...
|
||||
MouseArea {
|
||||
id: btnOK
|
||||
anchors.fill: parent
|
||||
onClicked:
|
||||
{
|
||||
containerqml.clickedfunc("李四");//调用page1.qml中的函数,实现了传返回值。
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
```
|
||||
另一种就是信号与槽
|
||||
|
||||
### QtQuick 母版页
|
||||
```
|
||||
//~ Panel.qml
|
||||
Item {
|
||||
|
||||
property alias headerHeight: headerLoader.height
|
||||
property alias footerHeight: footerLoader.height
|
||||
|
||||
property Component headerComponent: null
|
||||
readonly property Item headerItem: headerLoader.item
|
||||
|
||||
Loader {
|
||||
id: headerLoader
|
||||
width: parent.width
|
||||
height: 40
|
||||
sourceComponent: headerComponent
|
||||
Binding {
|
||||
target: headerLoader.item
|
||||
property: "anchors.fill"
|
||||
value: headerLoader
|
||||
}
|
||||
}
|
||||
|
||||
property Component footerComponent: null
|
||||
readonly property Item footerItem: footerLoader.item
|
||||
|
||||
Loader {
|
||||
id: footerLoader
|
||||
width: parent.width
|
||||
height: 40
|
||||
anchors.bottom: parent.bottom
|
||||
Binding {
|
||||
target: footerLoader.item
|
||||
property: "anchors.fill"
|
||||
value: footerLoader
|
||||
}
|
||||
}
|
||||
|
||||
property Component contentComponent: null
|
||||
readonly property Item contentItem: contentLoader.item
|
||||
|
||||
Loader {
|
||||
id: contentLoader
|
||||
width: parent.width
|
||||
anchors.top: headerLoader.bottom
|
||||
anchors.bottom: footerLoader.top;
|
||||
Binding {
|
||||
target: contentLoader.item
|
||||
property: "anchors.fill"
|
||||
value: contentLoader
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Panel {
|
||||
headerComponent: Rectangle {
|
||||
color: "black"
|
||||
}
|
||||
footerComponent: Rectangle {
|
||||
color: "black"
|
||||
}
|
||||
contentComponent: ListView {
|
||||
delegate: Rectangle { width: parent.width; height: 40; color: "green" }
|
||||
model: 10
|
||||
}
|
||||
}
|
||||
```
|
||||
### 全局单例模式
|
||||
|
||||
1. 入口文件的 id 和属性
|
||||
2. 静态 JavaScript 文件
|
||||
3. qml 单例,QML 实现
|
||||
4. qml 单例,c++ 实现
|
||||
5. 注册上下文属性
|
||||
|
||||
### 表单提交(不包括cookies)
|
||||
```
|
||||
function urlQuery(jsonObject) {
|
||||
var query = "";
|
||||
var i = 0;
|
||||
for(var iter in jsonObject) {
|
||||
|
||||
if(i > 0) {
|
||||
query += "&";
|
||||
}
|
||||
query += iter +"=" + encodeURI(jsonObject[iter]);
|
||||
i++;
|
||||
}
|
||||
// console.log("url query:", query);
|
||||
return query;
|
||||
}
|
||||
```
|
||||
```
|
||||
function setHeader(xhr, headers) {
|
||||
//"Content-Type":"application/x-www-form-urlencoded"
|
||||
for(var iter in headers) {
|
||||
xhr.setRequestHeader(iter, headers[iter]);
|
||||
}
|
||||
}
|
||||
|
||||
function ajax(method, url, headers, data, callable) {
|
||||
headers = headers || {};
|
||||
callable = callable || function(xhr) {
|
||||
console.log(xhr.responseText);
|
||||
}
|
||||
var xhr = new XMLHttpRequest;
|
||||
xhr.onreadystatechange = function() {
|
||||
if(xhr.readyState == xhr.DONE) {
|
||||
callable(xhr);
|
||||
}
|
||||
}
|
||||
xhr.open(method, url);
|
||||
setHeader(xhr, headers);
|
||||
if("GET" === method) {
|
||||
xhr.send();
|
||||
} else {
|
||||
xhr.send(data);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
如果带有指定名称的头部已经被指定了,这个头部的新值就是:之前指定的值,加上逗号、空白以及这个调用指定的值。
|
||||
如果 open() 调用指定了认证资格,XMLHttpRequest 自动发送一个适当的 Authorization 请求头部。但是,你可以使用 setRequestHeader() 来添加这个头部。类似地,如果 Web 服务器已经保存了和传递给 open() 的 URL 相关联的 cookie,适当的 Cookie 或 Cookie2 头部也自动地包含到请求中。可以通过调用 setRequestHeader() 来把这些 cookie 添加到头部。XMLHttpRequest 也可以为 User-Agent 头部提供一个默认值。如果它这么做,你为该头部指定的任何值都会添加到这个默认值后面。
|
||||
有些请求头部由 XMLHttpRequest 自动设置而不是由这个方法设置,以符合 HTTP 协议。这包括如下和代理相关的头部:
|
||||
Host
|
||||
Connection
|
||||
Keep-Alive
|
||||
Accept-charset
|
||||
Accept-Encoding
|
||||
If-Modified-Since
|
||||
If-None-Match
|
||||
If-Range
|
||||
Range
|
||||
|
||||
### XMLHttpRequest设置cookie的问题
|
||||
https://segmentfault.com/a/1190000004322487
|
||||
|
||||
### 如何获取指定objectName的QObject
|
Reference in New Issue
Block a user