zoukankan      html  css  js  c++  java
  • 20191014

    第五章   model/view
    组件显示/编辑数据的一种结构
    QListView QTreeView QTableView
    预定义数据模型
    QAbsstracItemModel类

    QStringListModel   
    QStandardItemModel  数据项
    QFileSystemModel   
    QSortFilterProxyModel  排序过滤
    QSqlQueryModel  
    QSqlTableModel  表
    QSqRelationalTableModel 
    QModelIndex模型索引的类
    持久性模型索引: QPersistentModelIndex
    获取索引的三个参数: 行号,列号,父项
    项的角色:
    void QStandItem::setData(const QVariant &value,int role = Qt::UserRole++1);

    QFileSystemModel *model = new QFileSystemModel;
    model->setRootPath(QDir::currentPath());

    1 创建一个模型,在视图中添加模型
    2 接受下表判断是否合法。
    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        themodel = new QStringListModel(this);
        QStringList theStrlist;
        theStrlist<<"北京"<<"上海"<<"合肥";
        themodel->setStringList(theStrlist);
        ui->listView->setModel(themodel);
       // ui->listView->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::SelectedClicked);  //设置可以编辑状态
        ui->listView->setEditTriggers(QAbstractItemView::NoEditTriggers);
    }
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    void MainWindow::on_addpushButton_clicked()
    {
        themodel->insertRow(themodel->rowCount());
        QModelIndex index = themodel->index(themodel->rowCount()-1,0);
        themodel->setData(index,"new item",Qt::DisplayRole);
        ui->listView->setCurrentIndex(index);
    }
    void MainWindow::on_editpushButton_2_clicked()
    {
        QModelIndex index = ui->listView->currentIndex();
        themodel->insertRow(index.row());
        themodel->setData(index,"insert item",Qt::DisplayRole);
       // ui->listView-setCurrentIndex(index);
        ui->listView->setCurrentIndex(index);
    }
    void MainWindow::on_pushButton_3_clicked()
    {
        QModelIndex index = ui->listView->currentIndex();
        themodel->removeRow(index.row());

    }
    void MainWindow::on_pushButton_clicked()
    {
        themodel->removeRows(0,themodel->rowCount());
    }
    void MainWindow::on_pushButton_2_clicked()
    {
        QStringList tmpList = themodel->stringList();
        ui->plainTextEdit->clear();
        for(int i=0;i<tmpList.count();i++)
        {
            ui->plainTextEdit->appendPlainText(tmpList.at(i));
        }
    }
    void MainWindow::on_listView_clicked(const QModelIndex &index)
    {
        ui->label->setText(QString::asprintf("当前条目:row= %d,column = %d",index.row(),index.column()));
    }

    QStandardItemModel
    QTableView
    QItemSelectionModel
     
    利用Curl向服务器发送请求:
    1 封装数据
    2 设置curl
    3 开启psot请求
    3 添加数据
    4 设定回调函数
    5 给回调函数一个参数
    6 等待回复
    7 处理响应
    8 定义一个结构体,接受回复数据

    Andriod studio app中:
    第一步:
    定义一个JNI接口类,实现单例模式。
    注册接口: public native boolean reg(String username, String passwd,String )
    第二步:
    进入项目文件,进入java, javah -jni  file 生成头文件
    第三步:
    添加.cpp文件
    添加头文件
    //防止变量名改变
    extern "c"
    {
     java方法转化为c
     把java数据转化为c数据
     const char *usrname = env->GetStringUFTChars(j_name,NULL);
     封装JSON数据:
     打印日志。
     添加curl类,创建curl对象。执行向后台发送数据。
     接受后台数据。
     解析后台数据。

     释放资源
     env->ReleaseStringUTFChars()
     
    }
    第四步 创建Json类
    void insert(string key,string value);
    string print();
    防止json进行拷贝,出现浅拷贝风险。  把拷贝函数和operator= 私用
    让jni支持stl 和c++11
    在Application.mk添加
    APP_STL := stlport_static
    APP_CFLAGS := -std=c++11

    匿名拷贝。先创建一个对象。用一个变量名接受。
    第五步  powershell 进入JNI文件夹 ndk build
    第六步  封装curl类
    方法: 发送数据
    成员函数含有this指针,去掉this指针的方法是加上static

    copy(p,p+count,back_inserter(char *str));
    尝试在str的尾部添加

    https  采用opnssl加密
    服务器公钥 服务器私钥   合法的CA证书
    第一步
    客户端  尝试连接   HTTPS服务器
    第二步
    HTTPS服务器   返回证书(服务器公钥,证书) 客户端
    客户端辨别CA证书的合法性,生成一对客户端的公钥,客户端的私钥
    第三步
    用服务器的公钥加密客户端的公钥和客户端的密钥
    用服务器的私钥解密得到客户端的公钥
    第四步
    用客户端的公钥生成一个与客户端的会话公钥
    第五步:
    客户端加密数据请求服务器
    第六步:
    用服务器的加密会话通信。
    https 加密过程
    第一步: 非对称加密认证数据
    第二部: 对称加密  加密算法openssl算法
    安装openssl

    demo写好的,在里面写callback.
    两个服务器:数据和业务。
    客户端: jni通信。 
    通信协议: /loggin json
        /reg json
        /order
    服务器间通信web与存储通信协议:
    /persistent json
    /cache 
    1 持久数据库 用户信息
    cmd:
    busi:
    tale:
    字段:
    用户表,接单表。
    2 缓存数据库
    HASH类型数据。
    redis.cn
    设置key,获取key

    vsp:sp
    grep name . -r --color  查询文件夹中包含字符串“name”的文件
    数据服务器:
    封装一个CJSON数据。
    表明。
     
    QSGContext::initialize: depth buffer support missing,expert rendering errors
    注册回调函数:
    定义结构体,接受数据。
    定义一个curl 指针。
    1 设置curl的路径。
    2 设置忽略openssl CA认真
    3 设置curl为post类型
    4 设置curl的数据
    5 设置回调函数
    6 设置形参
    提交请求向data服务器
    curl_easy_perform(curl)

    util.h
    公共函数
    git修改代码:
    第一步:
    git status
    第二步:
    git pull 更新本地代码
    第三步:
    git commit file.c -m"日志"
    第四部步:
    git push -u origin master
    添加:
    git add main.c 到本地版本控
    git commit main.c -m"原因"
    git pull 
    git push -u origin master

    回退版本:
    git stash
    git pull
    git stash pop
    解决冲突:
    git pull
  • 相关阅读:
    HTML5中表单的创建
    防冲撞协议原理实验报告
    yii2.0 Activeform表单部分组件使用方法 [ 2.0 版本 ]
    Yii正则验证
    Yii2用Gii自动生成Module+Model+CRUD
    yii2框架安装运行init.bat报错php.exe不是内部或外部命令
    YII2.0安装教程,数据库配置前后台 [ 2.0 版本 ]
    ignore_user_abort函数制定计划任务
    php 常用的系统函数
    php常用字符串处理函数
  • 原文地址:https://www.cnblogs.com/countryboy666/p/11675275.html
Copyright © 2011-2022 走看看