QT slot 所属线程

需求 qt 中 slot 可以有两种形式,一种是单独的一个函数,还有一种是 lambda 表达式,那么他们所属的线程是什么呢? 解决 单独的槽函数,所属线程是主线程 lambda 表达式,所属线程是发送信号对应的子线程。 参考 换了多种方法,还是没完美解决、、、

<span title='2023-06-24 07:55:00 +0800 CST'>2023-06-24</span>&nbsp;·&nbsp;1 min&nbsp;·&nbsp;13 words&nbsp;·&nbsp;RamLife

assert 宏用于单元测试

需求 在单元测试中,需要能够自动判断结果和预期是否相符,如果不符,就报错。 解决 可以直接参考 st 的 assert_param 宏,根据需要,自己改造下,增加了额外的自定义错误说明语句。 // assert #include <stdint.h> #ifdef USE_ASSERT #define ASSERT_FAIL(expr, msg) ((expr) ? (void)0U : assert_fail((char*) msg, (char*)__FILE__, __LINE__)) void assert_fail(char* msg, char* file, uint32_t line); #else #define ASSERT_FAIL(expr) ((void)0U) #endif /* USE_ASSERT */ #ifdef USE_ASSERT void assert_fail(char* msg, char* file, uint32_t line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ //SEGGER_RTT_printf(0, "assert_failed: file %s on line %d", file, line); Log::printf(Log::kError, "assert_failed1: file %s on line %d\n", file, line); while(1); } #endif /* USE_ASSERT */ void CurrentAverageTest() { ASSERT_FAIL((1 == 1), "CurrentAverageTest, result 1 error"); } 只要在编译参数中,增加 USE_ASSERT, 开启,即可使用宏来自动判断结果是否相符。...

<span title='2023-06-21 14:42:00 +0800 CST'>2023-06-21</span>&nbsp;·&nbsp;1 min&nbsp;·&nbsp;117 words&nbsp;·&nbsp;RamLife

git 普通仓库转为裸仓库

需求 普通项目目录中的 .git 仓库希望转为 gitea 之类所使用的裸仓库。 解决 使用 git clone --mirror 或者 git clone --bare. 两者的区别是: bare 会把仓库中已有的相应的分支整理出来。本地没有的分支和相关合并信息全部舍弃。 mirror 不管本地仓库中有没有这个分支,都把相关的分支和合并信息全部保留。 参考 如何将普通的Git仓库转换为裸仓库? How to convert a normal Git repository to a bare one? What’s the difference between git clone –mirror and git clone –bare When creating a git repository that will be on the server, can I convert it to a bare repository? {duplicate} {Git} 裸代码仓库和镜像代码仓库全解 git clone –mirror 和 git clone –bare 有什么区别

<span title='2023-06-20 15:44:00 +0800 CST'>2023-06-20</span>&nbsp;·&nbsp;1 min&nbsp;·&nbsp;74 words&nbsp;·&nbsp;RamLife

gitea actions 功能

需求 了解 gitea 的 ci/cd 需要用到的 actions 解决 gitea 推出了 Actions 来实现 CI/CD 方案。需要在 Gitea 1.19.0 及以上的版本才能支持。需要在 gitea/conf/app.ini 中添加如下配置: # 添加此配置 [actions] ENABLED = true 后面具体配置可以参考: Gitea Actions 搭建 Gitea Actions 带你体验 CI/CD 自动化工作流 体验 Gitea Actions 体验 Gitea Actions https://blog.gitea.com/2022/12/feature-preview-gitea-actions/ 参考

<span title='2023-06-20 15:44:00 +0800 CST'>2023-06-20</span>&nbsp;·&nbsp;1 min&nbsp;·&nbsp;42 words&nbsp;·&nbsp;RamLife

c++ R"()"

需求 C++ 中 R"()" 的作用? 解决 正常的字符串在写的时候,碰到特殊字符需要使用 \ 来进行转义,如果希望直接就是原始字符,那么就需要使用 R"()" 了。 QString json = "{\ \"error\": {\ \"code\": 101,\ \"message\" : \"operation failed!\"\ },\ \"result\" : false\ }"; QString json = R"({ "error": { "code": 101, "message": "operation failed!" }, "result": false })"; 参考 C++源码转义技巧 R"()"

<span title='2023-06-19 10:25:00 +0800 CST'>2023-06-19</span>&nbsp;·&nbsp;1 min&nbsp;·&nbsp;46 words&nbsp;·&nbsp;RamLife

c++ Wreorder

需求 编译时警告 warning "will be initialized after [-Wreorder] 解决 构造函数时,初始化成员变量的顺序与类声明中的变量顺序不对应,就会报这个错误。 参考 C++: warning “will be initialized after {-Wreorder} 警告: 在此处初始化后被初始化 {-Wreorder}

<span title='2023-06-19 10:25:00 +0800 CST'>2023-06-19</span>&nbsp;·&nbsp;1 min&nbsp;·&nbsp;21 words&nbsp;·&nbsp;RamLife

QT QObject 多线程问题

需求 qt 多线程编程时,经常碰到 QObject: Cannot create children for a parent that is in a different thread . 解决 正常就两种方法解决: 把这个 QObject 放到子线程中的 run 里面去创建和执行。 使用 moveToThread 把这个 QObject 转移给子线程。 参考 简单例子理解 Qt 中 QObject: Cannot create children for a parent that is in a different thread. 问题 【Qt】Qt出现QObject: Cannot create children for a parent that is in a different thread.问题 (Parent is QSerialPort(0x4ab1ab0), parent‘s thread is QThread(0xbe3860)……问题解决办法 Qt Socket多线程编程出现的问题

<span title='2023-06-19 07:55:00 +0800 CST'>2023-06-19</span>&nbsp;·&nbsp;1 min&nbsp;·&nbsp;69 words&nbsp;·&nbsp;RamLife

c++ 使用 sha1

需求 希望在 C++ 中使用 sha1 加密。 解决 openssl 也可以提供 sha1 加密,但是听说有滴血漏洞,所以考虑使用 cryptopp. 下载 cryptopp 之后,需要在 virtual studio 中编译,但是因为没有安装,并且我用的还是 mingw 编译环境,所以尝试在 qt 中编译。 使用 qt 命令行,切换到源码目录,然后 qmake --project 来生成 qt 工程。 使用 qt creator 打开之后,修改 pro 文件,把 TEMPLATE = app 改为 TEMPLATE = lib, 重新编译。 编译会有很多报错,基本都是 intel 的一些指令没有,可以去 https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#expand=3828 中搜索错误信息,然后找 CPUID Flags 这一行对应的提示,在这个提示前增加 -m 作为 flag, 放到 pro 文件中. 如下: QMAKE_CXXFLAGS += "-msse2" 有太多的报错, 所以暂时先放弃了,等后面有时间再搞。获取可以尝试安装 vs, 然后配置为 mingw 编译环境,也是一种办法。或者找找单纯的 sha1 加密库。...

<span title='2023-06-18 10:25:00 +0800 CST'>2023-06-18</span>&nbsp;·&nbsp;1 min&nbsp;·&nbsp;135 words&nbsp;·&nbsp;RamLife

QT sha1

需求 最近需要在 qt 中使用 sha1 加密。 解决 Qt 中已经提供了解决方法,就是 QCryptographicHash, 可以直接调用他的 hash 静态方法,只需要注明是 QCryptographicHash::Sha1 即可。 void MainWindow::on_pushButton_clicked() { QString id = ui->lineEdit->text(); QByteArray sha1 = QCryptographicHash::hash(id.toLocal8Bit(), QCryptographicHash::Sha1); string str = ptz::ByteArray2HexString((uint8_t*)sha1.data(), sha1.size()); QString pwd = QString::fromStdString(str); qDebug() << "byte array: " << sha1 << ", string: " << pwd << Qt::endl; ui->textBrowser->setText(pwd); } 参考 QT MD4 MD5 Sha1等几种加密方式 QCryptographicHash Class Secure Hash Algorithm SHA-1

<span title='2023-06-18 10:17:00 +0800 CST'>2023-06-18</span>&nbsp;·&nbsp;1 min&nbsp;·&nbsp;64 words&nbsp;·&nbsp;RamLife

QT 版本号

需求 最近需要在 qt 中获取版本号,根据版本号的不同,执行不同的语句。 解决 可以使用 QT_VERSION, QT_VERSION_STR, qVersion() 之类的。 #if (QT_VERSION <= QT_VERSION_CHECK(5,0,0)) ... #endif 参考 Qt程序中获取Qt的版本号信息 Qt之判断版本号宏「QT_VERSION」和「QT_VERSION_CHECK」

<span title='2023-06-18 10:17:00 +0800 CST'>2023-06-18</span>&nbsp;·&nbsp;1 min&nbsp;·&nbsp;19 words&nbsp;·&nbsp;RamLife