C++
文章平均质量分 56
brave_heart_lxl
这个作者很懒,什么都没留下…
展开
-
【C++】类中有指针类型的成员变量
如果一个类中有指针类型的成员变量,就要在构造函数中new动态分配内存,也需要在析构函数中delete释放内存。C++的2.6.2节。原创 2023-02-08 10:13:14 · 211 阅读 · 0 评论 -
QT 编译报错 invalid use of incomplete type class Ui::Login
解决方法是在其对应的ui文件中,整个界面的ObjectName没有进行更改,打开其对应的ui文件,果然发现objectname还是原始的form,将其ObjectName更改为Login即可。编译始终报错:invalid use of incomplete type class Ui::Login,啥情况,该包含的ui_.h文件也包含了,也setup了,流程一个都不少,真扎心,难道一上午辛辛苦苦弄得login.ui文件白费力,要重新弄不带UI的吗?报上面的问题,说明Ui::Login编译器不认识。原创 2023-02-02 15:07:54 · 1400 阅读 · 3 评论 -
Qt延时处理的四种方法
这种方法不会阻塞当前线程,尤其适合Qt的单线程带UI程序,或者UI线程,因为线程阻塞时,很明显的现象就是UI卡死。可以延时,但也会阻塞线程。它可以使得程序在while等待期间,去处理一下本线程的事件循环,处理事件循环最多100ms必须返回本语句,如果提前处理完毕,则立即返回这条语句。方法不会释放对象锁,其他线程无法访问对象,因此会阻塞线程;创建子事件循环,在子事件循环中,父事件循环仍然是可以执行的。上述代码使程序延时10 s,但是这种方法也会阻塞线程。方法会释放对象锁,使得其他线程能够访问该对象。原创 2022-11-25 09:32:44 · 2657 阅读 · 0 评论 -
Qt之延时总结
不够频繁的话,显然可能会使GUI线程的响应变差,例如每500ms才被调用一次,那么GUI的事件循环就只能500ms才被处理一次,当然,这个问题可以通过设定processEvents()的第二个形参略微得到缓解,更好的做法是,保证被调的周期原创 2022-11-25 09:25:55 · 3627 阅读 · 0 评论 -
QT (USBor其它)串口通信的实现方法
如果用qt写程序作为上位机,然后通过和usb和下位机通信的时候,就需要用到qt中的串口通信了。本文介绍了QT串口通信的实现方法,感兴趣的小伙伴们可以参考一下前言:如果用qt写程序作为上位机,然后通过和usb和下位机通信的时候,就需要用到qt中的串口通信了。使用qt中的串口通信的时候需要用到的两个头文件分别为:12除了加上面两个头文件之外,还需要在工程文件中加下面一行代码:1我们一般都需要先定义一个全局的串口对象,记得在自己的头文件中添加上:1。原创 2022-11-19 12:19:13 · 950 阅读 · 0 评论 -
QT中多线程槽函数在哪个线程中执行?
也是代码中注释掉的 moveToThread(this)所做的就是将整个 thread 类移到次线程中,去掉注释,你会发现slot在次线程中运行。可以看到,主线程id和slot_main()中的线程id是一样的,槽函数的线程和主线程是一样的!所以thread类中的slot_main()是在主线程执行,run()函数是在次线程执行。主线程(信号)QThread(槽), 但由于没说槽函数是在主线程执行的,所以不少人都认为它应该是在次线程执行了。run函数中的代码时确定无疑要在次线程中运行的,那么其他的呢?原创 2022-09-05 11:55:29 · 385 阅读 · 0 评论 -
Linux Qt程序打包发布(转)
在这里插入图片描述将copylib.sh复制到NewPro/platforms文件夹中,运行:./copylib libqxcb.so命令,同样生成lib文件夹(这里是libqxcb的依赖库,若缺少,将触发“xcb”错误),将lib文件夹下所有文件拷到NewPro目录下,遇到文件冲突选择全部替换。在这里插入图片描述将整个imageformats目录复制到NewPro目录中即可,同时,如果有预加载图片,也要一并放入NewPro中,若以qrc的形式加载,也要将qrc文件目录放到NewPro中。转载 2022-09-03 09:42:49 · 916 阅读 · 0 评论 -
使用linuxdeployqt在linux下进行Qt打包发布(超详细)题
举个例子:若存在程序A显式加载B.so,B.so隐式加载C.so,则对程序A使用linuxdeployqt拷贝依赖时,程序A的间接依赖文件C.so,将不会被拷贝。如果你的应用中,调用了其他的库,又想要放在某个指定目录下,那么可以在应用同目录下,添加qt.conf文件,指定库搜索路径。负责安装完成时的配置工作,软件安装完后,执行该Shell脚本,一般用来配置软件执行环境,必须以“#!deb包安装时,默认将内部文件,释放至根目录下(/),故我们需要在打包时,将安装目录层次创建好,以达到想要的安装路径效果。...原创 2022-08-08 19:27:11 · 701 阅读 · 0 评论 -
C++标准转换运算符static_cast
虽然const_cast是用来去除变量的const限定,但是static_cast却不是用来去除变量的static引用。其实这是很容易理解的,static决定的是一个变量的作用域和生命周期,比如:在一个文件中将变量定义为static,则说明这个变量只能在本Package中使用;在方法中定义一个static变量,该变量在程序开始存在直到程序结束;类中定义一个static成员,该成员随类的第一个对象出转载 2011-11-17 13:44:53 · 566 阅读 · 0 评论 -
C++规范之友员
Friend functionsIn principle, private and protected members of a class cannot be accessed from outside the same class in which they are declared. However, this rule does not affectfriends.Friend转载 2012-01-30 16:50:06 · 1015 阅读 · 0 评论 -
c++规范之多态
PolymorphismBefore getting into this section, it is recommended that you have a proper understanding of pointers and class inheritance. If any of the following statements seem strange to y转载 2012-01-30 16:47:13 · 1305 阅读 · 0 评论 -
C++规范之 预处理
Preprocessor directivesPreprocessor directives are lines included in the code of our programs that are not program statements but directives for the preprocessor. These lines are always pr转载 2012-01-30 16:59:16 · 948 阅读 · 0 评论 -
C++规范之字符数组
As you may already know, the C++ Standard Library implements a powerful string class, which is very useful to handle and manipulate strings of characters. However, because strings are in fact sequen转载 2012-01-31 09:59:36 · 625 阅读 · 0 评论 -
C++ virtual destructor
As you may know, in C++ a destructor is generally used to deallocate memory and do some other cleanup for a class object and it’s class members whenever an object is destroyed. Destructors are disting转载 2011-09-21 09:30:16 · 2996 阅读 · 0 评论 -
c++规范之 命名空间
Namespaces allow to group entities like classes, objects and functions under a name.This way the global scope can be divided in "sub-scopes", each one with its own name.The format of namespaces is转载 2012-01-30 17:01:33 · 695 阅读 · 0 评论 -
C++传引用数组
Passing an Array to a FunctionLast updated Jun 17, 2005.In aprevious column, I claimed that passing an array as a function argument was impossible. The problem is that the array is implicitly conv转载 2012-03-26 15:49:44 · 5974 阅读 · 0 评论 -
C++规范之 类型转化
Type CastingConverting an expression of a given type into another type is known as type-casting. We have already seen some ways to type cast:Implicit conversionImplicit conversions d转载 2012-01-30 16:54:28 · 797 阅读 · 0 评论 -
c++规范之 异常
Exceptions provide a way to react to exceptional circumstances (like runtime errors) in our program by transferring control to special functions calledhandlers.To catch exceptions we must place a转载 2012-01-30 17:03:52 · 697 阅读 · 0 评论 -
c++规范之模板
Function templatesFunction templates are special functions that can operate withgeneric types. This allows us to create a function template whose functionality can be adapted to more than one type o转载 2012-01-30 17:06:51 · 579 阅读 · 0 评论