Qt46 可复用查找对话框实现

C++QT入门_c++ qt ​ Qt 是一个跨平台的C++图形用户界面应用程序框架。它为应用程序开发者提供建立艺术级图形界面所需的所有功能。它是完全面向对象的,很容易扩展,并且允许真正的组件编程。常见GUI:QT:支持多平台开发;支持css;面向对象特性体现突出;发展趋势良好。MFC:只能在windows开发;运行程序效率高;库的安全性好;public slots: // 添加槽函数private:// 重新更新// 设置 完成之后可以拉伸。 阅读详情

学习自唐佐林老师Qt


在这里插入图片描述
在这里插入图片描述
在这里插入图片描述在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

FindDialog.h

#ifndef _FINDDIALOG_H_
#define _FINDDIALOG_H_

#include <QDialog>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QRadioButton>
#include <QCheckBox>
#include <QGroupBox>
#include <QPlainTextEdit>
#include <QPointer>
//查找对话框
class FindDialog : public QDialog
{
    Q_OBJECT

protected:
    QGroupBox m_radioGrpBx;//容器 用于放置两个单选按钮 QRadioButton

    //网格布局管理器,水平布局管理器
    QGridLayout m_layout;
    QHBoxLayout m_hbLayout;

    QLabel m_findLbl;//查找标签
    QLineEdit m_findEdit;//查找文本输入框
    QPushButton m_findBtn;//查找按钮 查找下一个
    QPushButton m_closeBtn;//关闭按钮
    QCheckBox m_matchChkBx; //复选框
    QRadioButton m_forwardBtn;//单选按钮 向前查找
    QRadioButton m_backwardBtn;//单选按钮 向后查找

    QPointer<QPlainTextEdit> m_pText;//智能指针指向 文本框对象
    void initControl();
    void connectSlot();
protected slots:
    void onFindClicked();//查找按钮 槽
    void onCloseClicked();//关闭按钮 槽
public:
    explicit FindDialog(QWidget* parent = 0, QPlainTextEdit* pText = 0);
    void setPlainTextEdit(QPlainTextEdit* pText);
    QPlainTextEdit* getPlainTextEdit();
    bool event(QEvent* evt);//重写事件处理
    
};

#endif // _FINDDIALOG_H_

FindDialog.cpp

#include "FindDialog.h"
#include <QEvent>
#include <QTextCursor>
#include <QMessageBox>


/*
  QDialog(parent, Qt::WindowCloseButtonHint | Qt::Drawer)
  窗口选项1:Qt::WindowCloseButtonHin 只显示一个关闭按钮
  窗口选项2:Qt::Drawe 当前对话框 不显示左上角图标
*/
FindDialog::FindDialog(QWidget *parent, QPlainTextEdit* pText)
    : QDialog(parent, Qt::WindowCloseButtonHint | Qt::Drawer)
{
    initControl();
    connectSlot();
    setLayout(&m_layout);
    setWindowTitle("Find");
    setPlainTextEdit(pText);
}

//界面布局
void FindDialog::initControl()
{
    m_findLbl.setText("Find What:");
    m_findBtn.setText("Find Next");
    m_closeBtn.setText("Close");
    m_matchChkBx.setText("Match Case");
    m_backwardBtn.setText("Backward");
    m_forwardBtn.setText("Forward");
    m_forwardBtn.setChecked(true);//默认被选取
    m_radioGrpBx.setTitle("Direction");//m_radioGrpBx容器 放置两个单选按钮 QRadioButton,设置标题

    //添加到水平布局管理器
    m_hbLayout.addWidget(&m_forwardBtn);
    m_hbLayout.addWidget(&m_backwardBtn);

    m_radioGrpBx.setLayout(&m_hbLayout);

    m_layout.setSpacing(10);
    m_layout.addWidget(&m_findLbl, 0, 0);
    m_layout.addWidget(&m_findEdit, 0, 1);
    m_layout.addWidget(&m_findBtn, 0, 2);
    m_layout.addWidget(&m_matchChkBx, 1, 0);
    m_layout.addWidget(&m_radioGrpBx, 1, 1);
    m_layout.addWidget(&m_closeBtn, 1, 2);

}

//映射信号到槽
void FindDialog::connectSlot()
{
    //映射信号 查找,关闭动作 到槽
    connect(&m_findBtn, SIGNAL(clicked()), this, SLOT(onFindClicked()));
    connect(&m_closeBtn, SIGNAL(clicked()), this, SLOT(onCloseClicked()));
}

void FindDialog::setPlainTextEdit(QPlainTextEdit* pText)
{
    m_pText = pText;
}

QPlainTextEdit* FindDialog::getPlainTextEdit()
{
    return m_pText;
}

//重写事件处理,点击关闭按钮 隐藏对话开关
bool FindDialog::event(QEvent* evt)
{
    //判断有没有收到 关闭 事件
    if( evt->type() == QEvent::Close )
    {
        hide();//隐藏当前对话框

        return true; //返回true 代表当前事件已经被处理了
    }

    return QDialog::event(evt);//其他事件 直接交给父类事件处理函数
}

//查找按钮 槽
void FindDialog::onFindClicked()
{
    QString target = m_findEdit.text();//获取需要查找的目标字符串

    if( (m_pText != NULL) && (target != "") )
    {
        QString text = m_pText->toPlainText();//取出文本框中所有字符
        QTextCursor c = m_pText->textCursor();//获取光标对象
        int index = -1;//标记字符串下标

        //向后查找
        if( m_forwardBtn.isChecked() )//如果向前查找按钮 被选择
        {
            /*查找目标字符串target
              从当前光标的位置开始查找 c.position
              是否大小写敏感查找  m_matchChkBx.isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive
                    CaseSensitive 大小写敏感
            */
            index = text.indexOf(target, c.position(), m_matchChkBx.isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive);

            //找到了目标字符串
            if( index >= 0 )
            {
                //从前向后查找,设置选择范围,光标属性 QTextCursor::KeepAnchor
                c.setPosition(index);
                c.setPosition(index + target.length(), QTextCursor::KeepAnchor);

                //设置选择好的光标信息
                m_pText->setTextCursor(c);
            }
        }

        //向前查找
        if( m_backwardBtn.isChecked() )
        {
            index = text.lastIndexOf(target, c.position() - text.length() - 1, m_matchChkBx.isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive);

            if( index >= 0 )
            {
                c.setPosition(index + target.length());
                c.setPosition(index, QTextCursor::KeepAnchor);

                m_pText->setTextCursor(c);
            }
        }

        //如果查找不到
        if( index < 0 )
        {
            QMessageBox msg(this);//提示对话框

            msg.setWindowTitle("Find");
            msg.setText("Can not find \"" + target + "\" any more...");
            msg.setIcon(QMessageBox::Information);
            msg.setStandardButtons(QMessageBox::Ok);//对话框按钮

            msg.exec();
        }
    }
}

//关闭按钮槽
void FindDialog::onCloseClicked()
{
    close();
}

定义指向查找对话框智能指针
QSharedPointer m_pFindDlg;

//初始化智能指针
m_pFindDlg(new FindDialog(this,&mainEditor))

//打开 查找对话框
m_pFindDlg->show();

在这里插入图片描述

在这里插入图片描述

Qt实战案例(46)——利用QTableWidget实现表格控件应用 在文章(Qt实战案例(26)——利用QTableView表格视图实现右击菜单删除功能)中介绍了利用QTableView表格视图和QStandardItemModel模型类实现右击菜单删除的事件过滤效果。 QTableView组件和QTableWidget组件的区别如下:由于QTableView组件相对QTableWidget组件来说只是不具备编辑功能,其他功能保持一致,QTableView组件支持与数据库建立映射关系,如果表格无需更新则最好可以使用QTableView组件。本文将介绍利用QTableWidg 阅读详情

相关推荐

ARM46与KylinOS下全能转换王开发全解析

本文介绍了基于ARM46处理器和KylinOS操作系统的全能转换王文档转换软件开发过程。文章重点分析了开发过程中面临的四大技术难点:跨平台兼容性问题、文档格式解析复杂性、性能优化以及用户界面设计,并提出了相应的解决方案。通过采用Qt框架、引入专业解析库、优化多线程处理和内存管理等技术手段,成功开发了支持多种文档格式转换的软件。该研究为特殊硬件平台下的软件开发提供了实践经验,未来将持续优化软件性能,提升用户体验。

L26477的博客 1077

Qt对话框QDialog之查找对话框

学习

passworddddddd的博客 402

Qt/C++编写自定义控件46-树状导航栏

一、前言 树状导航栏控件是所有控件中最牛逼最经典最厉害的一个,在很多购买者中,使用频率也是最高,因为该导航控件集合了非常多的展示效果,比如左侧图标+右侧箭头+元素前面的图标设置+各种颜色设置等,全部涵盖了,代码量也比较多,该控件前后完善了三年,还提供了角标展示文字信息,纵观市面上web也好,cs架构的程序也好,这种导航条使用非常多,目前只提供了二级菜单,如果需要三级菜单需要自行更改源码才行。 二、...

Qt/C++视频监控/推流/物联网/大屏系统/自定义控件/UI定制/输入法 5720

Qt开发-查找对话框的功能实现

(2)、所有与光标相关的信息都通过QTextCursor描述(如光标位置、文本选择等)(2)、lastIndexOf:从指定位置向前查找目标子串下标位置。(2)、QTextCursor对象保存了文本框中光标的相关信息。(4)、查找对话框和文本框的弱耦合关系满足了可复用的需求。(1)、indexOf:从指定位置向后查找目标子串下标位置。(1)、文本框中的光标是一个QTextCursor类的对象。(1)、QString提供了不同的子串查找方式。(2)、向前(向后)查找目标第一次出现的位置。

hw5230的博客 1103

Qt替换对话框

替换对话框,继承自查找对话框后实现,ReplaceDialog.

QtFindReplaceDialog-开源

QtFindReplaceDialog是“查找/替换Qt”对话框的实现,可在基于qt文本编辑的应用程序中使用。 对话框可以用作库,也可以简单地通过将源导入到自己的应用程序中来使用。

QT练习4:编写一个查找对话框

分为3个文件: finddialog.h: #ifndef FINDDIALOG_H#define FINDDIALOG_H#include &lt;QDialog&gt;class QCheckBox;class QLabel;class QLineEdit;class QPushButton;//自定义类,继承于QDialogclass FindDialog:public QDia...

weixin_34014277的博客 210

半导体制造技术导论(第二版)萧宏 第五章集成电路加热工艺答案

第二次退火是在较高温度下进行,并将电阻系数较高的c49碳化硅转变为电阻系数较低的c54碳。水平式高温炉加热、垂直式高温炉加热(即传统的管式炉加热)、快速加热工艺RTP、激光镭射。8. 集成电路芯片制造过程中,会使用垫底氧化层、阻挡氧化层、栅氧氧化层、屏蔽氧化层和全。氧化是最重要的加热过程之一,是一种添加工艺,将氧气加入到硅晶圆后,在晶圆表面形成二氧。为了满足元器件性能的要求,必须利用退火工艺将晶格的损伤修复,使其恢复单晶结构并激活掺。工艺氮气气流下将晶舟推入炉管,升高温度,稳定温度;

goal_achieving的博客 1864

Qt之自定义搜索框

转自http://blog.youkuaiyun.com/liang19890820/article/details/50357523 简述 关于搜索框,大家都经常接触。例如:浏览器搜索、Windows资源管理器搜索等。 当然,这些对于Qt实现来说毫无压力,只要思路清晰,分分钟搞定。 方案一:调用QLineEdit现有接口 void addAction(QAction * act...

xiaopei_yan的博客 1961

BEV感知技术全景解析:从纯视觉到多传感器融合的实战指南

本文全面解析了自动驾驶中的BEV感知技术,从纯视觉到多传感器融合的实战应用。文章深入探讨了BEV如何提供“上帝视角”,对比了IPM、Lift-Splat-Shoot及Transformer等核心实现范式,并详细阐述了多传感器融合(尤其是中融合)的工程实践与优势,为开发者提供了从理论到原型搭建的完整指南。

win55的博客 1141

SSCardDriver.dll社会保障卡读写终端接口规范38号文接口

********************获取设备及PSAM卡信息********************//********************获取银行账户信息 ********************//********************获取设备信息********************//********************PIN校验********************//********************通用写卡********************/

广东东信智能科技有限公司的专栏 1745

用QT写一个对话框

打开QT creater创建取名去findDialog的项目,这个项目要基于QDialog。直接上FindDialog.h的头文件。 1 #ifndef FINDDIALOG_H 2 #define FINDDIALOG_H 3 4 #include<QDialog> 5 #include<QtGui> 6 class QCheckBox; ...

weixin_30268071的博客 153

中科蓝讯蓝牙开发:从源码到固件的自动化构建链路解析

本文详细解析了中科蓝讯AB530X蓝牙芯片从源码到最终固件的完整自动化构建链路。通过剖析prebuild.bat、GCC编译、postbuild.bat等关键环节,阐述了资源打包、配置生成、代码编译与固件合成的全过程,并重点介绍了如何实现一键编译与自动下载,为开发者高效进行嵌入式蓝牙开发提供清晰指南。

weixin_29193259的博客 121

Qt5:创建对话框

以一个查找对话框为例子开始学习 用Qt创建一个对话框程序 首先使用手工编码创建一个查找对话框程序 1 #include "finddialog.h" 2 #include<QtGui> 3 4 FindDialog::FindDialog(QWidget *parent) : 5 QDialog(parent) 6 {  //查找窗口的...

weixin_30512785的博客 130

【3】 灰度变换(1)

第三章(1)【总三】

课题分离 659

10倍开发者的 Dify 魔法书:从零构建全栈 AI 应用

“不懂底层算法,也能开发爆款 AI 应用吗?” 答案是:绝对可以。 Dify 正在重新定义 AI 应用的开发范式——通过可视化的低代码平台,将原本需要数周的开发周期压缩到几小时。无论你是前端、后端、产品经理,还是渴望破局的独立开发者,这都是你不可错过的红利。 我们将手把手教你利用 Dify 快速接入百模大战,零代码搭建企业级知识库,并一键发布你的专属 AI 助手、智能客服和自动化工作流。 告别重复造轮子,掌握 Dify,一个人就是一支 AI 团队。现在上车,开启你的 10 倍速开发之旅!

davidwang456的专栏 684

linux qt 查找进程名,Qt实现的根据进程名来结束进程

1、头文件及实现部分:1 #include 2 #include 3 #include "psapi.h"4 #pragma comment(lib,"psapi.lib")56 #include 7 #include 89 int TerminateProcess(QString ProcessName, QString sPathName = "")10 {11 int res...

weixin_33002763的博客 1172

嵌入式Linux&Android开发-环境搭建

目录 一、环境要求 二、相关软件&SDK下载 三、环境安装 3.1 VMware Worksation 3.2 Ubuntu1804 3.3 VSCode安装 3.4 Samba服务器搭建 一、环境要求 编译 Android 对机器的配置要求较高: 64 位 CPU 大于12GB 物理内存+交换内存(最好16GB以上) 30GB 空闲的磁盘空间用于构建,源码树另外占用大约 25GB, 如果要编译源码则还需要 150GB 的磁盘空间。 RK官方推荐使用 Ubuntu 16..

嵌入式成长手册 550

day46

1. 什么是事件?(重点)事件是由窗口系统或者自身产生的,用以响应所发生的 各类事情,比如用户按下并释放了键盘或者鼠标、窗口因 暴露而需要重绘、定时器到时而应有所动作,等等从某种意义上讲,事件比信号更原始,甚至可以认为大多 数信号其实都是由事件产生的。比如一个下压式按钮首先 感受到的是鼠标事件,在进行必要的处理以产生按钮下沉 继而弹起的视觉效果之后,才会发射 clicked()信号2. 如何处理事件?(重点)

2201_75400389的博客 966

【软件定义汽车】-【架构篇】-全面讲解整车电子电气架构演进

前言: 前段时间,陆陆续续写了一些电子电气架构相关的文章。这里打算再写最后一篇作为收尾,为整个系列画上句号,把坑填上,这个话题就算过去了。后续一段时间,尽量把之前文章中挖的“坑”填一下。行文逻辑将借鉴5W2H进行。 另外,本文作为一篇整合性的文章,为保证逻辑的完整性,主要是将大量过去自己文章中的内容进行梳理整合,也存在很多行业内专家的公开文章的内容,请见谅。 WHAT1:什么是汽车电子电气架构? 电子电气架构:EEA,Electrical/Electronic Architecture.

零点壹客的博客 1万+

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

Qt对话框部分学习

一、对话框部分常用内容 颜色对话框、文件对话框、字体对话框、输入对话框、消息对话框、进度对话框、错误对话框、向导对话框。 二、代码部分 1 //widget.h 2 #ifndef MYWIDGET_H 3 #define MYWIDGET_H 4 5 #include <QWidget> 6 ...

weixin_30785593的博客 126

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

qt5.5实现 记事本程序

最近由于要做Qt相关的毕业设计课题,以前对Qt完全不了解,对于客户端图形界面程序,也只对Windows下的MFC熟悉, 所以,由于Qt的跨平台特性和相对比较纯的C++的特点,就准备学习一下吧。这两天逛了一下Qt的开发者官方网站,和一些国内的论坛, 看了下基本的知识点,比如信号和槽的机制,界面的布局,就想写个东西,巩固一下。于是参考了官方的文档和代码,纯代码实现了一个简易的记事本程序。...

297

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

系统常量对话框QT实现

1.运行结果: 2.代码 main.cpp 1 #include "constantdiag.h" 2 #include <QtWidgets/QApplication> 3 4 int main(int argc, char *argv[]) 5 { 6 QApplication a(argc, argv); 7 consta...

weixin_30462049的博客 151

Linux 学习记录46(QT篇)

pro是一个工程管理文件,依据这个文件来生成makefile文件来编译源文件#添加相关的类库,例如进程线程库、网络编程库、数据库等待 QT += core gui #默认提供两个类库: core包含了核心库,io相关操作等 gui库提供了图形化相关的类库 #如果qt版本超过4.0,就会多加一个widgets类库,大部分组件全部来自于该库 greaterThan(QT_MAJOR_VERSION, 4) : QT += widgets。

qq_59004923的博客 572

46黑马QT笔记之Qt下Tcp通信过程例子

46黑马QT笔记之Qt下Tcp通信过程例子 1 服务端: 1)头文件: #ifndef WIDGET_H #define WIDGET_H #include <QWidget> #include<QTcpServer> #include<QTcpSocket> namespace Ui { class Widget; } class Widget : pu...

weixin_44517656的博客 314
上一篇: Qt45 写一个可复用的查找对话框界面
下一篇: Qt47 调色板使用
Ma浩然
博客等级 码龄9年 1万+粉丝 462原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Ma浩然

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值