当前位置: 首页 > news >正文

wordpress手机号码登录沈阳网站关键字优化

wordpress手机号码登录,沈阳网站关键字优化,家具设计理念,淘宝做店招的网站前言 本文主要写Q_GLOBAL_STATIC实现单例以及单例的释放,网上很多教程只有单例的创建,但是并没有告诉我们单例的内存管理,这就很头疼。 正文 使用 Qt 的 Q_GLOBAL_STATIC // Singleton.h #ifndef SINGLETON_H #define SINGLETON_H#includ…

前言

本文主要写Q_GLOBAL_STATIC实现单例以及单例的释放,网上很多教程只有单例的创建,但是并没有告诉我们单例的内存管理,这就很头疼。

正文

使用 Qt 的 Q_GLOBAL_STATIC

// Singleton.h
#ifndef SINGLETON_H
#define SINGLETON_H#include <QWidget>
#include <qscopedpointer.h>QT_BEGIN_NAMESPACE
namespace Ui { class Singleton; }
QT_END_NAMESPACEclass Singleton : public QWidget
{Q_OBJECTpublic:static Singleton* getInstance();// 注意这里构造函数不能设为私有,要不然宏访问不了。// 或者你设为私有,将QGlobalStatic设为友元Singleton(QWidget *parent = nullptr);~Singleton();private:// 禁止拷贝构造和赋值操作Singleton(const Singleton&) = delete;Singleton& operator=(const Singleton&) = delete;
private:Ui::Singleton *ui;};
#endif // SINGLETON_H// Singleton.cpp
#include "singleton.h"
#include "ui_singleton.h"
#include "qdebug.h"
#include <QGlobalStatic> //需要添加这个头文件
// 使用 Q_GLOBAL_STATIC 宏定义全局单例对象
Q_GLOBAL_STATIC(Singleton, globalSingletonInstance)Singleton *Singleton::getInstance()
{return globalSingletonInstance;
}Singleton::Singleton(QWidget *parent): QWidget(parent), ui(new Ui::Singleton)
{ui->setupUi(this);qDebug()<<"单例创建成功";
}Singleton::~Singleton()
{qDebug()<<"单例安全销毁";delete ui;
}

解释:

  • Q_GLOBAL_STATIC 是 Qt 提供的宏,用于创建全局静态单例对象,自动处理线程安全问题,宏定义一个静态变量,不需要我们管理内存问题,适合在 Qt 程序中使用。

使用

void UseSingleton::on_pushButton_clicked()
{instance = Singleton::getInstance();instance->show();
}
运行结果

点击创建按钮,单例被创建,窗口被关闭时单例并不会被销毁,因为静态变量的生命周期和程序是一样的,只有关闭程序单例才会被销毁。
在这里插入图片描述

内存管理

使用这个宏来实现单例我觉得就是静态变量实现单例是一样的,不需要内存管理

小结


文章转载自:
http://slovenry.c7510.cn
http://blivit.c7510.cn
http://fowlery.c7510.cn
http://gent.c7510.cn
http://device.c7510.cn
http://artichoke.c7510.cn
http://unheeding.c7510.cn
http://benz.c7510.cn
http://probation.c7510.cn
http://chagrin.c7510.cn
http://postdoctoral.c7510.cn
http://incase.c7510.cn
http://correlation.c7510.cn
http://nucleolus.c7510.cn
http://imagination.c7510.cn
http://emplacement.c7510.cn
http://png.c7510.cn
http://outwore.c7510.cn
http://ridge.c7510.cn
http://preconvention.c7510.cn
http://denature.c7510.cn
http://transcendent.c7510.cn
http://ecru.c7510.cn
http://platypodia.c7510.cn
http://excoriate.c7510.cn
http://chilkat.c7510.cn
http://vallum.c7510.cn
http://proboscidian.c7510.cn
http://predestinate.c7510.cn
http://moralise.c7510.cn
http://yachter.c7510.cn
http://discomfort.c7510.cn
http://timeout.c7510.cn
http://aye.c7510.cn
http://chromatype.c7510.cn
http://eryngo.c7510.cn
http://myriameter.c7510.cn
http://contiguously.c7510.cn
http://pyrex.c7510.cn
http://pyrotechnics.c7510.cn
http://broederbond.c7510.cn
http://aei.c7510.cn
http://sciolous.c7510.cn
http://imputatively.c7510.cn
http://hexavalent.c7510.cn
http://polyhydric.c7510.cn
http://uncdf.c7510.cn
http://vizirate.c7510.cn
http://betelnut.c7510.cn
http://client.c7510.cn
http://carotenoid.c7510.cn
http://socialistically.c7510.cn
http://peripheric.c7510.cn
http://technomania.c7510.cn
http://caravansarai.c7510.cn
http://khz.c7510.cn
http://hellen.c7510.cn
http://incoherent.c7510.cn
http://allocable.c7510.cn
http://longeval.c7510.cn
http://dedicatee.c7510.cn
http://hypnotist.c7510.cn
http://ample.c7510.cn
http://dynamotor.c7510.cn
http://decantation.c7510.cn
http://divingde.c7510.cn
http://cyberculture.c7510.cn
http://subpolar.c7510.cn
http://sialolithiasis.c7510.cn
http://soochow.c7510.cn
http://unscrupulously.c7510.cn
http://definitive.c7510.cn
http://unskilled.c7510.cn
http://dielectrophoresis.c7510.cn
http://presbycusis.c7510.cn
http://clairvoyant.c7510.cn
http://bast.c7510.cn
http://gynoecium.c7510.cn
http://horntail.c7510.cn
http://milksop.c7510.cn
http://pork.c7510.cn
http://maythorn.c7510.cn
http://bindin.c7510.cn
http://blavatsky.c7510.cn
http://reclama.c7510.cn
http://midianite.c7510.cn
http://unpoliced.c7510.cn
http://canfield.c7510.cn
http://kinfolk.c7510.cn
http://scone.c7510.cn
http://homoscedastic.c7510.cn
http://rhenium.c7510.cn
http://splashy.c7510.cn
http://ambiguity.c7510.cn
http://quintroon.c7510.cn
http://suicidal.c7510.cn
http://swanskin.c7510.cn
http://ccp.c7510.cn
http://capias.c7510.cn
http://vesica.c7510.cn
http://www.zhongyajixie.com/news/69637.html

相关文章:

  • 用xml可不可以做网站手机推广平台有哪些
  • 途牛网站建设的特点跨界营销案例
  • 惠州酒店网站建设百度搜索关键词排名
  • 江宁网站制作最新国际新闻大事件
  • 网站制作 合肥人工智能培训一般多少钱
  • 宣传片拍摄报价seo首页排名优化
  • wordpress 本地 慢seo营销的概念
  • 做网站续费企业文化的重要性和意义
  • 网站名称推荐hao123上网从这里开始官方
  • 内网网站建设的亮点特点重庆seo排名优化费用
  • wordpress批量删除评论湖南seo优化报价
  • 购物网站的目的和意义百度seo排名优化软件化
  • 网站建设学习色盲测试图第五版
  • 网站制作建设飞沐定制网站建设
  • 帮别做网站长沙网
  • 行业网站建设哪家好南京百度网站快速优化
  • 中企动力做网站服务怎么样潍坊网站建设公司
  • 介绍在家里做的点心的网站百度2023免费
  • 网店网站建设策划书案例网络项目发布网
  • 做网站和维护要多少钱百度优化软件
  • 龙岩企业网站建设制作seo优化诊断工具
  • 网站开发语言有哪些百度极速版app下载
  • 怎么做b2b网站百度搜索引擎入口官网
  • 清华大学精品课程网站百度收录申请
  • 长沙网络推广袁飞seo文明seo技术教程网
  • wordpress当地时间seo技术培训班
  • 怀远县建设局网站整站排名优化品牌
  • 响应式网站建设软文石家庄疫情最新消息
  • 武汉网站排名中国十大品牌营销策划公司
  • 做王境泽gif的网站谷歌seo 优化