GHOST's Blog


  • 首页

  • 归档

  • 标签

  • 分类

  • 关于我

  • 搜索

QML 笔记

发表于 2023-01-18   |   分类于 日志   |   暂无评论

State

配合使用:state、states、PropertyChanges。

Item 属性:state 当前状态,states 定义所有状态。

非 Item 对象通过 StateGroup 来使用 State。

 Rectangle {
     id: signal
     width: 200; height: 200
     state: "NORMAL"

     states: [
         State {
             name: "NORMAL"
             PropertyChanges { target: signal; color: "green"}
             PropertyChanges { target: flag; state: "FLAG_DOWN"}
         },
         State {
             name: "CRITICAL"
             PropertyChanges { target: signal; color: "red"}
             PropertyChanges { target: flag; state: "FLAG_UP"}
         }
     ]
 }

when 属性:

 Rectangle {
     id: bell
     width: 75; height: 75
     color: "yellow"

     states: State {
                 name: "RINGING"
                 when: (signal.state == "CRITICAL")
                 PropertyChanges {target: speaker; play: "RING!"}
             }
 }

阅读全文 »

Qt Remote Objects (QtRO) 教程

发表于 2022-12-29   |   分类于 日志   |   暂无评论

简介

Qt Remote Objects (QtRO) 是 Qt 的一个进程间通信模块。

术语

Source 是指提供服务或提供功能供其他程序使用的对象,是 RPC 中的被调用端。

Replica 是指 Source 对象的代理对象,用于 RPC 中的调用端,对 Replica 的调用请求将被转发给 Source 对象。

示例1:Direct Connection using a Static Source

创建接口定义文件

创建接口定义文件 simpleswitch.rep :

class SimpleSwitch
{
  PROP(bool currState=false);
  SLOT(server_slot(bool clientState));
};

修改 .pro 文件

// 引入 QtRO 模块
QT += remoteobjects
// 引入接口定义文件
REPC_SOURCE = simpleswitch.rep

阅读全文 »

libcurl 笔记

发表于 2022-04-19   |   分类于 日志   |   暂无评论

https://curl.haxx.se/libcurl/c/libcurl-tutorial.html

基础

初始化,参数指定要初始化的模块:

curl_global_init(CURL_GLOBAL_ALL);

如果没有调用 curl_global_init,curl_easy_perform 会自动调用。

CURL_GLOBAL_WIN32
CURL_GLOBAL_SSL

当不再使用 libcurl 时调用:

curl_global_cleanup();

init 和 cleanup 避免重复调用,应只调用一次。

查询libcurl支持的特性:

curl_version_info();

libcurl 提供两种接口:

  1. easy interface - 函数以 curl_easy 为前缀,同步、阻塞调用。(let you do single transfers with a synchronous and blocking function call)
  2. multi interface - 支持在一个线程中多个传输任务,异步。(allows multiple simultaneous transfers in a single thread)

阅读全文 »

FFmpeg 笔记

发表于 2022-04-16   |   分类于 日志   |   暂无评论

基础概念

https://www.ruanyifeng.com/blog/2020/01/ffmpeg.html

码率

比特率,bps,每秒位数。

muxer

封装,把视频流、音频流、字幕流等封装到一个容器格式中。

demuxer

从容器格式中分离出流。

容器

视频文件本身其实是一个容器(container),里面包括了视频和音频,也可能有字幕等其他内容。

查看 ffmpeg 支持的容器:

ffmpeg -formats

编码格式

视频和音频都需要经过编码,才能保存成文件。不同的编码格式(CODEC),有不同的压缩率,会导致文件大小和清晰度的差异。比如H.264就是一种视频编码格式。

查看 ffmpeg 支持的编码格式:

ffmpeg -codecs

阅读全文 »

RapidJSON

发表于 2022-04-10   |   分类于 日志   |   暂无评论

http://rapidjson.org/zh-cn/

用法一览

// rapidjson/example/simpledom/simpledom.cpp
#include "rapidjson/document.h"
#include "rapidjson/writer.h"
#include "rapidjson/stringbuffer.h"
#include <iostream>
 
using namespace rapidjson;
 
int main() {
    // 1. Parse a JSON string into DOM.
    const char* json = "{\"project\":\"rapidjson\",\"stars\":10}";
    Document d;
    d.Parse(json);
 
    // 2. Modify it by DOM.
    Value& s = d["stars"];
    s.SetInt(s.GetInt() + 1);
 
    // 3. Stringify the DOM
    StringBuffer buffer;
    Writer<StringBuffer> writer(buffer);
    d.Accept(writer);
 
    // Output {"project":"rapidjson","stars":11}
    std::cout << buffer.GetString() << std::endl;
    return 0;
}

阅读全文 »

nlohmann-json

发表于 2022-04-10   |   分类于 日志   |   暂无评论

https://github.com/nlohmann/json/
https://json.nlohmann.me/features/arbitrary_types/

创建 json 对象

// create an empty structure (null)
json j;

// add a number that is stored as double (note the implicit conversion of j to an object)
j["pi"] = 3.141;

// add a Boolean that is stored as bool
j["happy"] = true;

// add a string that is stored as std::string
j["name"] = "Niels";

// add another null object by passing nullptr
j["nothing"] = nullptr;

// add an object inside the object
j["answer"]["everything"] = 42;

// add an array that is stored as std::vector (using an initializer list)
j["list"] = { 1, 0, 2 };

// add another object (using an initializer list of pairs)
j["object"] = { {"currency", "USD"}, {"value", 42.99} };

// instead, you could also write (which looks very similar to the JSON above)
json j2 = {
  {"pi", 3.141},
  {"happy", true},
  {"name", "Niels"},
  {"nothing", nullptr},
  {"answer", {
    {"everything", 42}
  }},
  {"list", {1, 0, 2}},
  {"object", {
    {"currency", "USD"},
    {"value", 42.99}
  }}
};

阅读全文 »

protobuf 序列化库

发表于 2022-04-08   |   分类于 日志   |   暂无评论

https://developers.google.cn/protocol-buffers/docs/cpptutorial

简介

首先编写.proto文件定义数据结构,然后用protobuf工具生成对应编程语言的序列化和反序列化代码。

随着数据格式版本的更新,protobuf会自动处理对旧格式的兼容。

定义 .proto 文件

syntax = "proto2"

package tutorial

message Person {
  optional string name = 1;
  optional int32 id = 2;
  optional string email = 3;

  enum PhoneType {
    MOBILE = 0;
    HOME = 1;
    WORK = 2;
  }

  message PhoneNumber {
    optional string number = 1;
    optional PhoneType type = 2 [default = HOME];
  }

  repeated PhoneNumber phones = 4;
}

message AddressBook {
  repeated Person people = 1;
}

阅读全文 »

《Head First Go》 笔记

发表于 2022-04-05   |   分类于 日志   |   暂无评论

Hello World

package main

import "fmt"

func main() {
  fmt.Println("Hello, World!")
}

典型的Go文件布局:

  1. package子句
  2. 任何import语句
  3. 实际代码

每个Go文件都必须以package子句开头。

每个Go文件都必须导入它引用的每个包。

Go文件必须只导入它们引用的包。

Go查找名为main的函数并首先运行。

Go中的所有内容都区分大小写。

Println函数是fmt包的一部分,因此Go需要在函数调用之前使用报名。

阅读全文 »

OSG 笔记

发表于 2022-02-27   |   分类于 日志   |   暂无评论

《OpenSceneGraph 3.0 Beginners Guide》 笔记
OSG-3.6.5 + VS2017

Hello World

#include <osgDB/ReadFile>
#include <osgViewer/Viewer>

int main()
{
    osg::ref_ptr<osg::Node> root = osgDB::readNodeFile("cessna.osg");

    osgViewer::Viewer viewer;
    viewer.setSceneData(root.get());

    return viewer.run();
}

阅读全文 »

vcpkg

发表于 2021-11-13   |   分类于 日志   |   暂无评论

https://zhuanlan.zhihu.com/p/153199835
https://www.zhihu.com/question/263416411

Linux下开发,用到什么依赖库,直接apt install xxx或dnf install xxx,依赖库和依赖库的依赖库等等立即准备就绪,好用到爆炸。python、node.js也都有类似的包管理器。而VS环境下需要自己下载各种依赖库的源码、编译,折腾半天,最后还不一定能用。

而vcpkg的诞生,给我们带来了福音。

简介

vcpkg 是 Microsoft 的跨平台开源软件包管理器,极大地简化了 Windows、Linux 和 macOS 上第三方库的配置与安装。如果项目要使用第三方库,建议通过 vcpkg 来安装它们。vcpkg 同时支持开源和专有库。

vcpkg 为我们处理好了各种软件包的依赖关系和编译配置,安装软件包时软件包源码被下载下来,并通过 CMake 在本地编译。目前官方和社区提供了对各种平台和编译器的支持。

安装

git clone https://github.com/microsoft/vcpkg
cd vcpkg 
.\bootstrap-vcpkg.bat

查询软件包

.\vcpkg.exe search xxx

安装软件包

.\vcpkg.exe install xxx

Flask-Restful 教程

发表于 2021-10-27   |   分类于 日志   |   暂无评论

https://flask-restful.readthedocs.io/en/latest/quickstart.html#full-example

A Minimal API

from flask import Flask
from flask_restful import Resource, Api

app = Flask(__name__)
api = Api(app)

class HelloWorld(Resource):
    def get(self):
        return {'hello': 'world'}

api.add_resource(HelloWorld, '/')

if __name__ == '__main__':
    app.run(debug=True)

运行程序:

$ python api.py
 * Running on http://127.0.0.1:5000/
 * Restarting with reloader

测试API:

$ curl http://127.0.0.1:5000/
{"hello": "world"}

阅读全文 »

CMake 教程

发表于 2021-10-25   |   分类于 日志   |   暂无评论

使用系统环境变量

$ENV{PATH}

指定项目名称

相当于VS中的解决方案名称。

project(sqlitebrowser)

指定最低支持的CMake版本

cmake_minimum_required(VERSION 2.8.7)

设置变量

set(QSCINTILLA_DIR libs/qscintilla/Qt4Qt5)

set(SQLB_HDR
    src/version.h
    src/sqlitetypes.h
    src/csvparser.h
    src/sqlite.h
    src/grammar/sqlite3TokenTypes.hpp
    src/grammar/Sqlite3Lexer.hpp
    src/grammar/Sqlite3Parser.hpp
)

使用变量

${SQLB_HDR}

添加一个可执行程序项目

${PROJECT_NAME}指project指令中设置的名称。

add_executable(${PROJECT_NAME}
    ${SQLB_HDR}
    ${SQLB_SRC}
    ${SQLB_FORM_HDR}
    ${SQLB_MOC}
    ${SQLB_RESOURCES_RCC}
    ${SQLB_MISC}
)

添加预处理器定义

add_definitions(-DENABLE_SQLCIPHER)
add_definitions(-std=c++11)

if语句

if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE "Release")
endif()

阅读全文 »

C++/CLI 教程

发表于 2021-08-29   |   分类于 日志   |   暂无评论

《Visual C++/CLI 从入门到精通》 笔记

什么是C++/CLI

C++/CLI是C++和 .Net Framework 平台版本,它对标准C++进行了一些修改。标准C++允许的一些操作在C++/CLI中是不允许的(例如不能从多个基类继承),并进行了一些修改以支持.NET功能(例如接口和属性)以及兼容.Net运行时。

选择C++/CLI有两个重要理由。首先是互操作性,C++/CLI简化了将标准C++代码集成到.NET项目的步骤。其次是现在有了C++标准模板库(STL)的.NET版本,熟悉STL编码的人很容易迁移到.NET。

定义托管类

ref class Animal
{
public:
    int legs;
};

ref关键字用于简化与 .NET Framework 组件的交互。在class关键字前添加ref,类就成了托管类。实例化对象时,会在“公共语言运行时”(CLR)堆上创建对象。对象的生存期由 .NET Framework 的垃圾回收器管理。

也可以定义非托管类,即不加ref关键字。

创建托管类对象

Animal cat, dog;

句柄

在C++/CLI中,是“运行时”帮你管理内存,C++/CLI没有了传统的“指针概念”。相反是用句柄来包含变量的地址。使用gcnew操作符动态创建对象。

定义一个指向Animal对象的句柄:

Animal ^dog = gcnew Animal;
dog->legs = 4;

阅读全文 »

Python 实例

发表于 2021-08-06   |   分类于 日志   |   暂无评论

实例网站

https://www.programcreek.com/python/

读写文件

写文件

#!/usr/bin/env python3

with open('test.txt', 'w') as f:
    f.write('hello\n')
    f.write('python')

读文件

#!/usr/bin/env python3

with open('test.txt', 'r') as f:
    for l in f.readlines():
        print(l, end='')

遍历文件夹下的所有文件

#!/usr/bin/env python3

import pathlib
import pprint

pprint.pprint(list(pathlib.Path().rglob("*")))

阅读全文 »

pypi 镜像使用帮助

发表于 2021-05-23   |   分类于 日志   |   暂无评论

https://mirrors.tuna.tsinghua.edu.cn/help/pypi/

临时使用

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package

注意,simple 不能少, 是 https 而不是 http

设为默认

升级 pip 到最新的版本 (>=10.0.0) 后进行配置:

pip install pip -U
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

如果您到 pip 默认源的网络连接较差,临时使用本镜像站来升级 pip:

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -U

C++11 Lambda表达式

发表于 2021-05-10   |   分类于 日志   |   暂无评论

https://www.cnblogs.com/jimodetiantang/p/9016826.html
https://blog.csdn.net/qq_26079093/article/details/90759175

语法

capture mutable -> return-type { statement }

示例

[] (int x, int y) { return x + y; } 
[] (int x, int y) -> int { int z = x + y; return z; }

capture

[空]        没有任何函数对象参数。
[=]         函数体内可以使用 Lambda 所在范围内所有可见的局部变量(包括 Lambda 所在类的 this),并且是值传递方式(相当于编译器自动为我们按值传递了所有局部变量)。
[&]         函数体内可以使用 Lambda 所在范围内所有可见的局部变量(包括 Lambda 所在类的 this),并且是引用传递方式(相当于是编译器自动为我们按引用传递了所有局部变量)。
[this]      函数体内可以使用 Lambda 所在类中的成员变量。
[a]         将 a 按值进行传递。按值进行传递时,函数体内不能修改传递进来的 a 的拷贝,因为默认情况下函数是 const 的,要修改传递进来的拷贝,可以添加 mutable 修饰符。
[&a]        将 a 按引用进行传递。
[a, &b]     将 a 按值传递,b 按引用进行传递。
[=, &a, &b] 除 a 和 b 按引用进行传递外,其他参数都按值进行传递。
[&, a, b]   除 a 和 b 按值进行传递外,其他参数都按引用进行传递。

Crow Web框架

发表于 2021-05-09   |   分类于 日志   |   暂无评论

https://crowcpp.org

Crow is C++ microframework for web. (inspired by Python Flask)

入门

#include "crow.h"

int main()
{
    crow::SimpleApp app;

    CROW_ROUTE(app, "/")([](){
        return "Hello world";
    });

    app.port(18080).multithreaded().run();
}

JSON Response

CROW_ROUTE(app, "/json")
([]{
    crow::json::wvalue x;
    x["message"] = "Hello, World!";
    return x;
});

Arguments

CROW_ROUTE(app,"/hello/<int>")
([](int count){
    if (count > 100)
        return crow::response(400);
    std::ostringstream os;
    os << count << " bottles of beer!";
    return crow::response(os.str());
});

Handler arguments type check at compile time

// Compile error with message "Handler type is mismatched with URL paramters"
CROW_ROUTE(app,"/another/<int>")
([](int a, int b){
    return crow::response(500);
});

Handling JSON Requests

CROW_ROUTE(app, "/add_json")
.methods("POST"_method)
([](const crow::request& req){
    auto x = crow::json::load(req.body);
    if (!x)
        return crow::response(400);
    int sum = x["a"].i()+x["b"].i();
    std::ostringstream os;
    os << sum;
    return crow::response{os.str()};
});

阅读全文 »

boost.asio 笔记

发表于 2021-05-09   |   分类于 日志   |   暂无评论

《Boost.Asio C++ Network Programming》

libtorrent 使用了 Boost.Asio

支持

network
com serial ports
files

实现同步/异步输入输出

read(stream, buffer)
async_read(stream, buffer)
write(stream, buffer)
async_write(stream, buffer)

协议

TCP UDP IMCP

可以根据自己的需要扩展使其支持自己的协议

同步和异步

如果使用同步模式,因为是阻塞模式,所以服务器客户端往往使用多线程

编程前尽早决定使用同步还是异步模式



阅读全文 »

pugixml

发表于 2021-05-07   |   分类于 日志   |   暂无评论

https://pugixml.org/docs/quickstart.html

加载XML文件

pugi::xml_document doc;

pugi::xml_parse_result result = doc.load_file("tree.xml");

std::cout << "Load result: " << result.description() << ", mesh name: " << doc.child("mesh").attribute("name").value() << std::endl;

加载错误处理

pugi::xml_document doc;
pugi::xml_parse_result result = doc.load_string(source);

if (result)
{
    std::cout << "XML [" << source << "] parsed without errors, attr value: [" << doc.child("node").attribute("attr").value() << "]\n\n";
}
else
{
    std::cout << "XML [" << source << "] parsed with errors, attr value: [" << doc.child("node").attribute("attr").value() << "]\n";
    std::cout << "Error description: " << result.description() << "\n";
    std::cout << "Error offset: " << result.offset << " (error at [..." << (source + result.offset) << "]\n\n";
}

从内存加载XML

const char source[] = "<mesh name='sphere'><bounds>0 0 1 1</bounds></mesh>";
size_t size = sizeof(source);

// You can use load_buffer_inplace to load document from mutable memory block; the block's lifetime must exceed that of document
char* buffer = new char[size];
memcpy(buffer, source, size);

// The block can be allocated by any method; the block is modified during parsing
pugi::xml_parse_result result = doc.load_buffer_inplace(buffer, size);

// You have to destroy the block yourself after the document is no longer used
delete[] buffer;

阅读全文 »

Dear ImGui

发表于 2021-01-02   |   分类于 日志   |   暂无评论

Dear ImGui

https://github.com/ocornut/imgui

Dear ImGui 是一个即时渲染GUI组件。

即时渲染:游戏代码里有个游戏循环,每次循环就是一帧,一般玩游戏谈的每秒多少帧就是每秒执行了多少次游戏循环。在循环中可以处理用户输入、模型渲染、界面渲染、物理模拟等等。

而 Dear ImGui 就是一个UI渲染库。

GitHub上各路神仙上传的截图真的好炫酷。

贴一张官方的Demo截图:

ImGui Demo截图

QtImGui

找到了一个能将ImGui集成到QtWidget上的项目。

https://github.com/seanchas116/qtimgui

QtImGui 截图

123
GHOST

GHOST

使命召唤

46 文章
1 分类
52 标签
CSDN Gitee GitHub
友情链接
阮一峰的网络日志Hanny's Blog
© 2023 GHOST   京ICP备15044070号-1
Typecho
主题 - NexT.Pisces