zoukankan      html  css  js  c++  java
  • 引用传参

    #include "widget.h"
    #include <QVBoxLayout>
    #include <QDebug>
    Widget::Widget(QWidget *parent)
        : QWidget(parent)
    {
        QPushButton *button=new QPushButton(QString::fromLocal8Bit("Button"),this);
        QVBoxLayout *layout=new QVBoxLayout(this);
        layout->addWidget(button);
        setLayout(layout);
        myScanf(m_list);
        connect(button,&QPushButton::clicked, this, &Widget::myPrint);
        resize(200, 100);
    }
    void Widget::myScanf(QList<QStringList> &list)
    {
        for(int i=0;i<5;i++)
        {
            QStringList strList;
            for(int j=0;j<9;j++)
            {
                strList<<QString("hrlok %1").arg(j);
            }
            list.append(strList);
        }
    }
    
    void Widget::myPrint()
    {
        for(int i=0; i<m_list.size();i++)
           qDebug()<<m_list.at(i);
    }
    #ifndef WIDGET_H
    #define WIDGET_H
    
    #include <QWidget>
    #include <QList>
    #include <QStringList>
    #include <QString>
    #include <QPushButton>
    
    class Widget : public QWidget
    {
        Q_OBJECT
    
    public:
        Widget(QWidget *parent = 0);
        ~Widget(){};
        void myScanf(QList<QStringList> &list);
        QList<QStringList> m_list;
    protected slots:
        void myPrint();
    };
    
    #endif // WIDGET_H
    #include "widget.h"
    #include <QApplication>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        Widget w;
        w.show();
    
        return a.exec();
    }
    按键按下,输出
    ("hrlok 0", "hrlok 1", "hrlok 2", "hrlok 3", "hrlok 4", "hrlok 5", "hrlok 6", "hrlok 7", "hrlok 8")
    ("hrlok 0", "hrlok 1", "hrlok 2", "hrlok 3", "hrlok 4", "hrlok 5", "hrlok 6", "hrlok 7", "hrlok 8")
    ("hrlok 0", "hrlok 1", "hrlok 2", "hrlok 3", "hrlok 4", "hrlok 5", "hrlok 6", "hrlok 7", "hrlok 8")
    ("hrlok 0", "hrlok 1", "hrlok 2", "hrlok 3", "hrlok 4", "hrlok 5", "hrlok 6", "hrlok 7", "hrlok 8")
    ("hrlok 0", "hrlok 1", "hrlok 2", "hrlok 3", "hrlok 4", "hrlok 5", "hrlok 6", "hrlok 7", "hrlok 8")
  • 相关阅读:
    Java并发编程:synchronized
    对一致性Hash算法,Java代码实现的深入研究
    在Xcode中使用Git进行源码版本控制
    这些 Git 技能够你用一年了
    简明 Git 命令速查表
    Git 分支管理是一门艺术
    2016年Web前端面试题目汇总
    iOS 面试基础题目
    Json数据交互格式介绍和比较
    SpringBoot端口和访问路径
  • 原文地址:https://www.cnblogs.com/wangbin-heng/p/10067595.html
Copyright © 2011-2022 走看看