随笔分类 - Qt写好的代码
QVariant::UserType QVariant自定义数据类型的深入认识
摘要:1 /************************************************* 2 Copyright: zhm_xxbs@2022 3 Author: 张洪铭 4 Date: 2022年08月07日 5 Description:主要围绕QVariant类型,编写代码深入认
阅读全文
采用QSharedMemory实现多进程间的通信 Linux | window
摘要:直接上代码:简单的很 1 ///////////////////////////////////////////////////////////////////// 2 /// file: ProcessCommunicate.h 3 /// Description:本文采用<QSharedMemo
阅读全文
Qt 调试信息、打印信息、输出到文本
摘要:void debug_msg(QVariant msg) { static int i = 0; QFile file("debug_msg.txt"); if (i == 0) { i = 1; file.open(QFile::WriteOnly | QFile::Truncate | QFile::Text); } else { file.open(QFile::WriteOnly | QF
阅读全文
QThread 采用moveToThread方式实现多线程。 线程本身、connect关联的槽函数、connect关联的lambda对象分别运行在哪个线程中。
摘要:Qt如何实现多线程:https://www.cnblogs.com/azbane/p/11372531.html September 5,2019 先抛出几个问题,用问题来引导思维导向: 1、继承的QObject子类,和QThread对象,是在哪个线程创建的?(即:QObject子类对象和QThre
阅读全文
QHBoxLayout 、QFormLayout 遍历子部件,查找QLineEdit控件
摘要:布局如下: QLineEdit * edit1 = new QLineEdit; QLineEdit * edit2 = new QLineEdit; QLineEdit * edit3 = new QLineEdit; QLineEdit * edit4 = new QLineEdit; QFormLayout * formLayout1 = new QFormLayout; QFormLayo
阅读全文
C++ new delete 一维数组 二维数组 三维数组
摘要:h----------------------------- #include "newandmalloc.h" #include using namespace std; newAndMalloc::newAndMalloc() { cout using namespace std; newAndMalloc::newAndMalloc() { cout #include...
阅读全文
C++ 重写虚函数的代码使用注意点+全部知识点+全部例子实现
摘要:h-------------------------- #ifndef VIRTUALFUNCTION_H #define VIRTUALFUNCTION_H /* * 派生类中覆盖虚函数的使用知识点 * 1、返回值必须相同。 一个特例,返回值为本类类型的引用或指针,且可转为基类类型。 * 参见: * ...
阅读全文
Qt QDataTime QString 两个类的使用
摘要:QDateTime now = QDateTime::currentDateTime(); QString nowStr; nowStr = now.toString("yyyyMMdd_hhmmss"); QString fName = QString("debug_%1.log") .arg(no...
阅读全文
定时器事件QtimerEvent 随机数 qrand Qtimer定时器
摘要:QTimerEvent类:定时器事件。QObject的子类都可使用 int QObject::startTimer(int interval)【参数:毫秒】【返回值:定时器整型编号】来开启一个定时器。定时器溢出是,触发timerEvent()函数。 QTimer类:定时器。编程中更常用。提供更高层次
阅读全文
键盘事件
摘要:实现效果: 1、按下 Ctrl + M 组合键 最大化窗口 ;按下Shift + M 组合键 正常化窗口 ; 按下Alt + M 最小化窗口; 2、窗口上放置一个按钮,实现按下键盘四个方向键,移动按钮。 效果1: 效果2:上、下、左、右,单方向的移动OK的,但是,45°斜着运动,不是很灵。好奇怪
阅读全文
事件的传递 键盘事件作为例子
摘要://widget.h #ifndef WIDGET_H #define WIDGET_H #include #include"mylineedit.h" #include namespace Ui { class Widget; } class Widget : public QWidget { Q_OBJECT public: explicit Widget(QW...
阅读全文
创建工具条ToolBar
摘要:/***ToolBar***/ QToolBar * tlb_ImageOpen; QToolBar * tlb_VideoOpen; QToolBar * tlb_AudioOpen; void MainWindow::createToolbar() { tlb_ImageOpen = addToolBar(tr("Image")); tlb_Image...
阅读全文
文件打开对话框
摘要:QFileDialog dlg(this); dlg.setWindowTitle(tr("打开图片")); dlg.setWindowIcon(QIcon(":/main/res/图片.png")); dlg.setNameFilter(tr("ALL Image Type files(*.png *.jpg *.bmp *.jpeg *.gif *.psd)"...
阅读全文