• Qt 利用XML文档,写一个程序集合 二


    接上一篇文章https://www.cnblogs.com/DreamDog/p/9213915.html

    XML文档的读写

    一个根节点,下面每一个子节点代表一个子程序,内容为子程序名字,图标路径,exe路径

    /*
     * 读取XML配置文档
     */
    static int count_flag = 0;
    void MainWindow::read_XML()
    {
        QFile file("./subroutine/config.xml");                             //引用文件路径
        if(!file.open((QFile::ReadOnly | QFile::Text)))         //只读文本方式打开
        {
            QMessageBox::information(NULL,"Title","OpenFile false");        //如果打开失败则提示
        }
        /*
         * 装在XML文件内容到内存
         */
        QDomDocument doc;
        doc.setContent(&file);
        file.close();
        QDomElement root = doc.documentElement();
        QDomNode node = root.firstChild();
        QString name = "asd";
        QString iconpath;
        QString exepath;
        while (!node.isNull())
        {
            QDomElement element = node.toElement();
            if(!element.isNull())
            {
                QDomNamedNodeMap list = element.attributes();
                for(int i = 0;i<list.count();i++)
                {
                    if(list.item(i).nodeName() == "name")
                    {
                        name = list.item(i).nodeValue();
                    }
                    else if (list.item(i).nodeName() == "iconpath")
                    {
                        iconpath = list.item(i).nodeValue();
                    }
                    else if (list.item(i).nodeName() == "exepath")
                    {
                        exepath = list.item(i).nodeValue();
                    }
                }
            }
            //        QPushButton *button = new QPushButton(name, this);
            //        button->setIcon(QIcon(iconpath));
            //        button->show();
            //        connect(button,&QPushButton::clicked,[=]()
            //        {
            //            QProcess *myProcess = new QProcess(this);
            //            myProcess->startDetached(exepath);
            //        });
    
            MPushButton *button = new MPushButton(this);
            button->set_name(name);
            button->set_ICON(iconpath);
            button->show();
    
            connect(button,&MPushButton::clicked,[=]()
            {
                QProcess *myProcess = new QProcess(this);
                myProcess->startDetached(exepath);
            });
            flowLayout->addWidget(button);
            node = node.nextSibling();
            count_flag++;
            if(count_flag-35>0)
            {
                showWidgt->setGeometry(0,0,ui->widget_main->width(),ui->widget_main->height()+100*((count_flag-35)/7+1));
            }
    
        }
    }
    

     以上代码为读取XML部分,

     可以参考https://blog.csdn.net/z609932088/article/details/71694709

  • 相关阅读:
    必须转载 PHP & memcached 太精彩了,看一遍就能入门
    SYSID 来指定当前system
    How to increase the JES2 spool size
    JOBPARM SYSAFF的用处
    使用多Volume来创建一个dataset
    如何解决db2nodes.cfg line number “1”, Reason code “10”
    epdf macro to remove comments
    如何停止重复的job
    mysql数值类型
    (九)solr实现autocomplete功能
  • 原文地址:https://www.cnblogs.com/DreamDog/p/9214052.html
Copyright © 2020-2023  润新知