Tuesday, 1 October 2024

Translating a Qt application, can be a daunting task. This is an overview from Qt 5 to Qt 6 and what new functionality Qt 6.7 brings.
Continue reading Translating Qt Applications at basysKom GmbH.

Translating a Qt application, can be a daunting task. This is an overview from Qt 5 to Qt 6 and what new functionality Qt 6.7 brings.
Continue reading Translating Qt Applications at basysKom GmbH.
After having participated to both Qt Contributor Summit and Akademy, I ended up going to a few more conferences in September.
I went to Nextcloud Conference just after going back from Akademy. Unfortunately I was quite tired from Akademy and Qt Contributor Summit and I only stayed Saturday morning. Still it was great to meet some old colleagues there.

The Matrix Conference happened the weekend after the Nextcloud conference. This was the first Matrix Conference and a gathering of all types of actors involved in Matrix. From the grassroots community to companies deploying Matrix based solutions to their customers. The NeoChat team was there and we were super productive into bringing back the Android version, thanks to the help of Volker Krause. This resulted in many patches in NeoChat itself but also one patch in Kirigami.
Special mention to the food and coffee offered at the conference, which was always excellent and either vegan or vegetarian. Outside of the venue, food was also execellent with a lot of middle eastern food choice.
Here some photos of the event and the food:
It was my second time going to the Linux Days in Dornbirn and while the weather wasn’t as welcoming as last time, the local Linux community was again super welcoming!
During the event, I did a talk in German about Plasma 6. This was my first time doing a talk in German and I hope I did okay. I also hosted a KDE stand with Simon Österle, who offered his help with the stand. His help has been invaluable to me, so huge thanks to him.
Like last year, after the conference, all helpers, presenters and stand holders went to a local restaurent to enjoy Käsespätzle. It was again delicious.
Here some photos of the event and the food:
This release focuses on SiteSettings feature, so I will try to introduce it here.
This feature tries to enable per site configuration / settings of multiple options per website host / domain. It consist of having global / default options and site / local settings.
These options can be changed for the given site in the “Site Info” dialog.

The default options for HTML5 can be changed in “Preferences > Privacy”

The default QtWebEngine / site options can be changed in the Browsing tab or in place where they where configured until now.

In the preferences it is only possible to change existing modified permissions for given sites. At the moment it is not possible to manually add sites to the list, this can only be done from within “Site Info” dialog.
These features will be done at a later unspecified date.
The Amarok Development Squad is happy to announce the immediate availability of Amarok 3.1.1, the first bugfix release for Amarok 3.1 "Tricks of the Light"!
3.1.1 features a number of small improvements and bug fixes, including miscellaneous fixes for toolbars and the return of tag dialog autocompletions, a functionality that initially got lost during the Qt5/KF5 port. However, most of the work has again happened under the hood to improve the codebase's Qt6/KF6 compatibility. For the 3.2 version coming up later this year, the KDE frameworks dependency will be raised to 5.108. This should allow replacing the remaining deprecated KF5 functionalities; one of the final barriers preventing Qt6/KF6 based builds from succeeding.
In addition to source code, Amarok is available for installation from many distributions' package repositories, which are likely to get updated to 3.1.1 soon, as well as the flatpak available on flathub.
You can find the tarball package on download.kde.org and it has been signed with Tuomas Nurmi's GPG key.
Three weeks ago, I attended KDE Akademy 2024 in Würzburg, Germany. It was pretty exciting to meet my KDE friends after one year since last Akademy 2023!
Ideally whole trip should’ve taken just ~18 hours door-to-door but thanks to Lufthansa whole travel turned out to be of 48 hours in total including layovers. Flight cancellation and rebooking caused by travel to start way earlier than planned (Thursday 5:00 AM instead of planned 07:00 PM) and had to spend insane amount of time in layover.
This year Akademy was in Würzburg (shock! horror!). I think its not too far fetched to say that we pulled it successfully.
During last years Akademy in Thessaloniki the idea came up given the high density of KDE people in the area to hold Akademy in Würzburg. On top we had the perfect venue in mind: two lecture halls for talks, BoF rooms and a ample common area for people to hack and socialize. I had such thoughts in the back of my mind for a while but did not share or go through with them.
However what Akademy does is it makes you talk to people and Tobias convinced it me that we should do it and more people even agreed that Akademy in Würzburg would be a good idea! (Of course some of these encouragers this does not mean work organizing Akademy like it would mean for us…) So on the second-to-last day of Akademy I sat down and wrote an email to my former university professor to enquire about the possibility of doing Akademy in the building that we envisioned.
And just like that, after some informal talks during Akademy and a meeting at the University and sending in a proposal after the Call for Hosts later you end up having weekly meetings to talk about and plan the next installment of Akademy.
There were some problems but I think all in all this year Akademy went very well. I heard so much praise and positive feedback it felt a bit surreal at first (as did Sunday evening when all the talks were done). The most stressful situation for me happened on Sunday afternoon when I retrieved my charging phone from the team room to discover that the social event could not go ahead as planned and trying to manage that with the rest of the team. I think the resulting evening was very nice and chill and you could feel my relieve. I heard there was even an afterparty afterwards at the bar where we had held the welcome event.
Of course during the event there are always minor issues that need dealing with and looking out for those, dealing with them and trying to make sure everything is running smoothly (and the stress coming these things) meant that I couldn’t (and was not in the right state of mind) to focus much on the talks. When the BoF days started this was bit better but only on Thursday after the day trip I felt in a ‘conference mood’ and was able to focus fully on the BoFs that I was attending and sit down and hack a bit. If you want to learn more about the actual conference many people have blogged about it on the planet or read the report on the Akademy website.
In the end I think it’s fair to say that Akademy was a success. Made possible by KDE e.V. (go donate!), the sponsors, all the people of the Akademy team local and non-local, all the Volunteers on short and on long notice an last but not least all the awesome attendees - there would be no Akademy without any people. Thank you to you all! I am excited to learn about where next years Akademy will be (you can do it as well - it’s not hard and you get an awesome award on top) and looking forward to attending it as ‘normal Attendee’ and meeting everyone again there (if not earlier).
在客户端因某些原因异常退出时,服务端将无法正常处理其他请求.
recv一直在阻塞着读取,且无法处理其他请求如何往线程池中传入类的成员函数.
auto task = [](){ 类的成员函数 } m_pool.submit(task);1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
* `Tcp`传输为字节流传输,采用在每条消息前面加上`长度`来正确接收每条请求.
* 在代码中往`redis`数据库中添加好友申请数据时,没有正确插入.
* 由于好友申请当中包含时间,姓名等信息,中间含有**空格**,在redis的哈希表中无法插入.
* 经过查阅在redis哈希表中,**空格**可以用`+`代替,在遇到`+`时会被转义为**空格**,或者存储为**十六进制**,但是这种方法在终端中的**空格**为灰色.
* 在聊天界面如果输入带有`%`,服务器直接挂掉.
* ```c++
int redisAsyncContext::Lpush(const std::string &key, const std::string &value)
{
//std::string cmd = "lpush " + key + " " + value;
this->m_reply = (redisReply *)redisCommand(this->m_connettion, "LPUSH %s %s", key.c_str(), value.c_str());
// 检查 m_reply 是否为 NULL
if (this->m_reply == NULL) {
std::cerr << "Error: redisCommand returned NULL" << std::endl;
return -1; // 或其他合适的错误值
}
// 检查 m_reply 类型
if (this->m_reply->type != REDIS_REPLY_INTEGER) {
std::cerr << "Error: Expected integer reply" << std::endl;
freeReplyObject(this->m_reply);
return -1; // 或其他合适的错误值
}
int num = this->m_reply->integer;
freeReplyObject(this->m_reply);
std::cout << "G" << std::endl;
return num;
}
在执行下面两句是,%会被替换为cmd.c_str(),导致无法将消息插入历史记录表,导致出现错误.
1 | std::string cmd = "lpush " + key + " " + value; |
只要更改为下面即没有问题
1 | this->m_reply = (redisReply *)redisCommand(this->m_connettion, "LPUSH %s %s", key.c_str(), value.c_str()); |
在某次测试时,新注册账号id为0614897828,导致与该账号聊天的账号进入聊天界面时,0614897828发送的消息会在他人界面显示为通知消息.
0614897828聊天时,数据库中记录账号为614897828.score字段字符串中的0去除.将从字符串的首位非0开始存储.在进入好友私聊界面时,客户端新建了来接收消息,同时主线程发消息,主线程通过判断用户是否键入Esc来退出聊天界面,在输入Esc时,接收消息线程无法正确回收,无法退出聊天界面.
Esc时,将标志位设置为false,但由于客户端的recv为阻塞,导致无法及时获取到标志位的更改.Esc时,服务器向客户端发送退出信号,这样就可以正确及时的获取到标志位的更改,从而正确退出.在进行发送文件时,服务器会先将文件存储在本地,但是服务器存储的文件会多写入一些信息,导致接收文件大小偏大.
实现后台发送文件,由于会有实时刷新的存在,会导致文件发送不准确.
socket连接到服务器,在将发送这个文件交给另外一个线程socket发送文件后,服务器不用手动断开连接,服务器有心跳检测,会在一段时间后断开.是一个Linux系统调用,也是一种进程间通信(IPC)机制,主要通过使用文件描述符生成和使用事件通知.
提供了一种在不同进程之间或同一进程内的线程之间的同步事件的方法.
异常是程序在执行期间产生的问题。c++异常是指在程序运行时发生的特殊情况.
异常提供了一种转移程序控制权的方式。C++ 异常处理涉及到三个关键字:try、catch、throw
关键字:try、catch、throw。
catch: 在您想要处理问题的地方,通过异常处理程序捕获异常。catch 关键字用于捕获异常
try: try 块中的代码标识将被激活的特定异常。它后面通常跟着一个或多个 catch 块
1 | try |
SIGPIPE 是一种信号,当一个进程尝试向一个已经关闭的或不可写的管道或套接字写数据时,会触发这个信号。默认情况下,接收到 SIGPIPE 信号的进程会终止。这在网络编程中会导致一些问题,因为如果客户端断开连接,服务器进程在写入数据时会因为这个信号而意外退出。
在网络编程中,特别是使用套接字进行通信时,忽略 SIGPIPE 信号是一个常见的做法。这样可以防止进程因为 SIGPIPE 信号而意外终止。相反,程序可以通过检测 send 或 write 操作的返回值来处理错误,从而使程序更加健壮。
初始客户端构思方面的缺陷,导致实时消息没有线程及时接收。
当前处理方式为服务端将通知消息放入数据库当中,客户端在登陆之后,增加一个线程来定时执行刷新函数,刷新数据库中的通知消息
可以优化为在客户端登陆之后,采用多线程的方式来处理相关操作.
目前只有在历史消息这一操作涉及到redis+mysql的处理方式.
可以将一些重要信息也采用redis+mysql的处理方式(涉及到redis的存储方式,redis存储于内存当中,会造成数据丢失的情况)
可以考虑将redis全部做为缓存的形式,将重要信息与历史消息类似,达到一定情况下放入mysql,使数据更加的持久化.
继续学习epoll的相关内容.
了解其余网络框架,使得该项目的服务端更加的健壮.
了解消息队列的信息同步的问题.
熟悉零拷贝的过程,以及零拷贝的具体实现.
序列化的相关协议,json与其他序列化的区别、json的优点,以及为什么不用其他的序列化
数据库的深入学习,了解redis的缓存穿透、缓存雪崩、缓存击穿。加强对mysql数据库的学习.
加强对网络协议相关知识的学习.
C++提供了四个强制类型转换的关键字:
static_castconst_castreinterpret_cast1 | static_cast<目标类型>(表达式) |
1 | int num = 2; |
该运算符将表达式转换为目标类型。但没有进行运行时类型检查来保证转换的安全性。
主要用法
int与char,安全性也需要程序员来保证1 | class Person |
const_cast是c++中专用于处理与const相关的强制类型转换的关键字
其功能为:为一个变量重新设定其const描述.
即:const_cast可以为一个变量强行增加或删除其const限定.
需要明确的是,即使用户通过const_cast强行去除了const属性,也不代表当前变量从不可变变为了可变。const_cast只是使得用户接管了编译器对于const限定的管理权,故用户必须遵守“不修改变量”的承诺。如果违反此承诺,编译器也不会因此而引发编译时错误,但可能引发运行时错误。
volatile和__unaligned属性。1 | class Student |
在const成员函数fun()中,编译器将“this”视为“ const student const this”,即“this”是指向常量对象的常量指针,因此编译器不允许通过以下方式更改数据成员“这个”指针。const_cast将“this”指针的类型更改为“student const this”。
const_cast比简单类型转换更安全。从某种意义上讲,如果强制类型与原始对象不相同,则强制转换不会发生,这是比较安全的。
1 | int a=20; |
reinterpret,即重新解释.
该强制类型转换的作用是提供某个变量在底层数据上的重新解释.
当我们对一个变量使用reinterpret_cast后,编译器将无视任何不合理行为,强行将被转换变量的内存数据重解释为某个新的类型。用于进行各种不同类型的指针之间、不同类型的引用之间以及指针和能容纳指针的整数类型之间的转换。转换时,执行的是逐个比特复制的操作。 它不检查指针类型和指针所指向的数据是否相同。
需要注意的是,reinterpret_cast要求转换的两个数据所占用的内存大小一致,否则会引发编译时错误.
1 | data_type *var_name = reinterpret_cast <data_type *>(pointer_variable); |
使用 reinterpret_cast 的目的:
1 | class A { |
dynamic用于在运行时实现向下类型转换。
1 | dynamic_cast <type-id> (expression) |
将expression转换为type-id类型,type-id必须是类的指针,类的引用或者是void,
如果type-id是一个指针,那么expression也是一个指针,是引用的话同为引用
特点如下:
nullptr。static_cast的效果是一样的。在进行父类指针向子类指针的转换时,dynamic_cast具有类型检查的功能,比static_cast更安全。dynamic_cast操作符则可以在运行期对可能产生问题的类型转换进行测试。1 | class AA { |
匿名函数是很多高级语言都支持的概念,如lisp语言在1958年首先采用匿名函数。匿名函数有函数体,但没有函数名。C++11中引入了lambda表达式。利用lambda表达式可以编写内嵌的匿名函数,用以替换独立函数或者函数对象,并且使代码更可读。但是从本质上来讲,lambda表达式只是一种语法糖,因为所有其能完成的工作都可以用其它稍微复杂的代码来实现。但是它简便的语法却给C++带来了深远的影响。如果从广义上说,lamdba表达式产生的是函数对象。
相同类似功能我们也可以使用函数对象或者函数指针实现:函数对象能维护状态,但语法开销大,而函数指针语法开销小,却没法保存范围内的状态。lambda表达式正是结合了两者的优点。
1 | // 完整语法 |
lambda表达式标记为mutable后,函数体就可以修改传值方式捕获的变量;lambda表达式是一个常量函数;lambda表达式可以抛出的异常;lambda表达式的特性;标号1. 函数声明了一个const类型的表达式,此声明不可改变capture list中的捕获的值。
标号2. 函数省略了返回值,此时如果function body内含有return语句,则按return语句返回类型决定返回值类型,若无则返回值为void类型。
标号3. 函数无参数列表,意味无参函数。
1 | vector<int> vec{1,0,9,5,3,3,7,8,2}; |
lambda表达式最前面的方括号的意义何在?其实这是lambda表达式一个很Hong要的功能,就是闭包。这里我们先讲一下lambda表达式的大致原理:每当你定义一个lambda表达式后,编译器会自动生成一个匿名类(这个类当然重载了()运算符),我们称为闭包类型(closure type)。那么在运行时,这个lambda表达式就会返回一个匿名的闭包实例,其实一个右值。所以,我们上面的lambda表达式的结果就是一个个闭包。闭包的一个强大之处是其可以通过传值或者引用的方式捕捉其封装作用域内的变量,前面的方括号就是用来定义捕捉模式以及变量,我们又将其称为lambda捕捉块。
Lambda表达式可以捕获外面变量,但需要我们提供一个谓词函数([capture list]在声明表达式最前)。类似参数传递方式:值传递、引入传递、指针传递。在Lambda表达式中,外部变量捕获方式也类似:值捕获、引用捕获、隐式捕获。
1 | int a = 123; |
值捕获和参数传递中的值传递类似,被捕获的值在Lambda表达式创建时通过值拷贝的方式传入,类中会相应添加对应类型的非静态数据成员。在运行时,会用复制的值初始化这些成员变量,从而生成闭包。因此Lambda表达式函数体中不能修改该外部变量的值; 因为函数调用运算符的重载方法是const属性的。同样,函数体外对于值的修改也不会改变被捕获的值。 想改动传值方式捕获的值,那么就要使用mutable。
1 | auto add_x = [x](int a) mutable { x *= 2; return a + x; }; // 复制捕捉x |
因为一旦将lambda表达式标记为mutable,那么实现的函数调用运算符是非const属性的。
1 | int a = 123; |
引用捕获的变量使用的实际上就是该引用所绑定的对象,因此引用对象的改变会改变函数体内对该对象的引用的值。 对于引用捕获方式,无论是否标记mutable,都可以在lambda表达式中修改捕获的值。
隐式捕获有两种方式,分别是 [=]:以值补获的方式捕获外部所有变量 [&]:表示以引用捕获的方式捕获外部所有变量。
1 | int a = 123, b=321; |
| 捕获外部变量形式 | |
|---|---|
| [ ] | 不捕获任何变量(无参函数) |
| [变量1,&变量2, …] | 值(引用)形式捕获指定的多个外部变量 |
| [this] | 值捕获this指针 |
| [=, &x] | 变量x以引用形式捕获,其余变量以传值形式捕获 |
| [*this] | 通过传值方式捕获当前对象 |
| [&, x] | 默认以引用捕获所有变量,但是x是例外,通过值捕获 |
既然只使用一次,那直接写全代码不就行了,为啥要函数呢?——因为lambda可以捕获局部变量
在上面的捕获方式中,注意最好不要使用[=]和[&]默认捕获所有变量。首先说默认引用捕获所有变量,你有很大可能会出现悬挂引用(Dangling references),因为引用捕获不会延长引用的变量的声明周期:
1 | std::function<int(int)> add_x(int x) |
因为参数x仅是一个临时变量,函数调用后就被销毁,但是返回的lambda表达式却引用了该变量,但调用这个表达式时,引用的是一个垃圾值,所以会产生没有意义的结果。如果通过传值的方式来解决上面的问题:
1 | std::function<int(int)> add_x(int x) |
使用默认传值方式可以便面悬挂引用问题.但是采用默认值捕获所有变量仍然有风险。例如当在类中捕获私有变量,当返回值为lambda表达式时,无法捕获到私有变量,但当指定为[=]时,会捕获到this指针的副本,当类已经调用析构函数,使用该指针仍然不安全.
单一的return语句可以推断返回类型;多语句则默认返回void,否则报错,应指定返回类型
1 | // 正确,单一return语句 |
auto和function可接受lambda表达式的返回:
1 | int x =8,y=9; |
lambda表达式产生的类不含有默认构造函数、赋值运算符、默认析构函数。至于闭包类中是否有对应成员,C++标准中给出的答案是:不清楚的,看来与具体实现有关。还有一点要注意:lambda表达式是不能被赋值的:
1 | auto a = [] { cout << "A" << endl; }; |
因为禁用了赋值操作符:
1 | ClosureType& operator=(const ClosureType&) = delete; |
但是没有禁用复制构造函数,所以可以用一个lambda表达式去初始化另外一个lambda表达式而产生副本。并且lambda表达式也可以赋值给相对应的函数指针,这也使得你完全可以把lambda表达式看成对应函数类型的指针。
在C++14中,lambda又得到了增强,一个是泛型lambda表达式,一个是lambda可以捕捉表达式。
lambda表达式可以按复制或者引用捕获在其作用域范围内的变量。而有时候,我们希望捕捉不在其作用域范围内的变量,而且最重要的是我们希望捕捉右值。所以C++14中引入了表达式捕捉,其允许用任何类型的表达式初始化捕捉的变量:
1 | // 利用表达式捕获,可以更灵活地处理作用域内的变量 |
可以看到捕捉表达式扩大了lambda表达式的捕捉能力,有时候你可以用std::move初始化变量。这对不能复制只能移动的对象很重要,比如std::unique_ptr,因为其不支持复制操作,你无法以值方式捕捉到它。但是利用lambda捕捉表达式,可以通过移动来捕捉它:
1 | auto myPi = std::make_unique<double>(3.1415); |