• UI
  • mainwindow.h
     #ifndef MAINWINDOW_H
    #define MAINWINDOW_H #include <QMainWindow>
    #include <QStringListModel> namespace Ui {
    class MainWindow;
    } class MainWindow : public QMainWindow
    {
    Q_OBJECT public:
    explicit MainWindow(QWidget *parent = );
    ~MainWindow(); private slots:
    //按下按钮
    void on_pushButton_clicked();
    22   //combox改变
    23 void on_comboBox_currentIndexChanged(int index);

    private:
    Ui::MainWindow *ui;
    27 //设置列表
    28 QStringList *sl;
    29 //设置模式,显示列表
    30 QStringListModel *slm;
    }; #endif // MAINWINDOW_H
  • mainwindow.cpp
     #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QStringListModel> MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    10 sl = new QStringList();
    11 sl->append("hello1");
    12 sl->append("hello2");
    13 sl->append("hello3");
    14 sl->append("hello4");
    15 //创建字符串模式
    16 slm = new QStringListModel(this);
    17 slm->setStringList(*sl);
    18 //显示
    19 ui->listView->setModel(slm);
    20
    21 //设置combox选项
    22 ui->comboBox->insertItem(0,"hello1","hello1");
    23 ui->comboBox->insertItem(1,"hello2","hello2");
    24 ui->comboBox->insertItem(2,"hello3","hello3");
    25 ui->comboBox->insertItem(3,"hello4","hello4");

    } MainWindow::~MainWindow()
    {
    delete ui;
    } void MainWindow::on_pushButton_clicked()
    { QString qstr;
    39 qstr = ui->lineEdit->text();
    40 sl->append(qstr);
    41 //模式设置字符串
    42 slm->setStringList(*sl);
    43 //显示
    44 ui->listView->setModel(slm);
    } void MainWindow::on_comboBox_currentIndexChanged(int index)
    {
    //获取当前数据
    50 QString myqstr=ui->comboBox->currentText();
    51 ui->lineEdit->setText(myqstr);
    }
  • main.cpp
     #include "mainwindow.h"
    #include <QApplication> int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    MainWindow w;
    w.show(); return a.exec();
    }

最新文章

  1. MongoDB使用锦集
  2. CLR via C#深解笔记二 - 类型设计
  3. iisapp 命令 弹出 iisschlp.wsc [88,25] 属性值无效 progid
  4. 新手自学ABAP(1)--数据类型
  5. 黑马程序员_Java面向对象_内部类
  6. Android学习笔记27:网格视图GridView的使用
  7. linux下tomcat shutdown后 java进程依然存在
  8. python练习题-员工信息表
  9. 吴裕雄 03-mysql连接
  10. Hadoop家族学习路线、实践案例
  11. 最近玩Bootstrap , 一些小工具 记录在案。
  12. LeetCode 27 Remove Element (移除数组中指定元素)
  13. MNIST机器学习入门【学习笔记】
  14. Spring框架的事务管理的分类
  15. shell统计各省的百强县
  16. 各排序算法的Java实现及简单分析
  17. Linux Guard Service - 守护进程的作用、用途、父进程标识的特点
  18. jsp电子商务系统之六 订单篇1
  19. shell 获取hive表结构
  20. POJ:2456-Aggressive cows

热门文章

  1. [lua]异步串行流程*协程
  2. 异步lambda表达式
  3. T对象序列化后T对象中属性字段不见了?
  4. 洛谷P2607 [ZJOI2008]骑士(树形dp)
  5. python课程设计笔记(五) ----Resuests+BeautifulSoup (爬虫入门)
  6. deepin下jdk和tomcat的安装教程
  7. (转)Webpack2 + Vue2 + Vue-Router2 如何实现懒加载?
  8. 修改ElementUI源码
  9. hdu4009 Transfer water 最小树形图
  10. vue项目布局