加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

通过读取xml文件存储的可执行文件描述符,获取可执行文件名称,

发布时间:2020-12-16 05:01:30 所属栏目:百科 来源:网络整理
导读:m_mvaAnalysisAction = new QAction(tr("mva Analysis"),this); connect(m_mvaAnalysisAction,SIGNAL(triggered()),this,SLOT(parallelSlot())); m_parallelActions-addAction(m_mvaAnalysisAction); int CKsMPSActions::parallelSlot(){ // 获得XML文件,Bi
  m_mvaAnalysisAction = new QAction(tr("mva Analysis"),this);
  connect(m_mvaAnalysisAction,SIGNAL(triggered()),this,SLOT(parallelSlot()));
  m_parallelActions->addAction(m_mvaAnalysisAction);
 
int CKsMPSActions::parallelSlot()
{
    // 获得XML文件,Bin文件根目录
    QString sXMLPathName,szBinPath;
    QString exeName;//可执行文件名
    QList <QString> exeStrList,describeList;//可执行文件列表,可执行文件相对应的描述符列表
    if (!CKsPathManager::GetVelocityXMLPath(sXMLPathName))
        return -1;

    // 读XML文件,获得bin文件夹下的可执行文件列表,可执行文件相对应的描述符列表
    CKsPathManager::InitCategroy(sXMLPathName,exeStrList,describeList);

    // 规避无效值
    int iCount = exeStrList.size();
    if (iCount == 0)
    {
        QMessageBox::warning(0,tr("Warning"),tr("Job execute failed!"));
        return 1;
    }

    //可执行文件所在的根目录,即bin目录
    if( !CKsPathManager::GetExecFilePath(szBinPath))
        return -1;
    //
    if(describeList.contains(tr("mva Analysis")))
    {
        exeName = exeStrList.at(describeList.indexOf(tr("mva Analysis")));

    //
#ifdef Q_WS_WIN32
    	szBinPath += exeName;
#else
    	szBinPath = szBinPath +"/" + exeName;
#endif
    	//
    	szBinPath = szBinPath.trimmed();
    	if( !QProcess::startDetached(szBinPath) )
   	{
        	QMessageBox::warning(0,tr("Job execute failed!"));
       	 	return 2;
    	}
} else { QMessageBox::warning(0,tr("Job execute failed!")); return 1; } return 0;}


char *CKsPathManager::m_pVelocityInitFile = "velocity.xml";
// 获得速度XML文件路径
bool CKsPathManager::GetVelocityXMLPath(QString& sXMLPath)
{
    QString sLocTemp;
    if (GetModuleInitPath(sLocTemp) == false)
        return false;
    sXMLPath += sLocTemp;
    sXMLPath += CKsPathManager::m_pVelocityInitFile;

    return true;
}


void CKsPathManager::InitCategroy(QString szFileName,QList<QString> &listCategory,QList<QString> &listDescribe)
{
    QFile file(szFileName);
    QDomDocument domDocument;

    QString errorStr;
    int errorLine;
    int errorColumn;

    //设置QFile
    if (!domDocument.setContent((QIODevice  *)&file,true,&errorStr,&errorLine,&errorColumn)) {

        return;
    }
    QDomElement root = domDocument.documentElement();
    if (root.tagName() == "xml")
        if (root.hasAttribute("version")
            && root.attribute("version") == "1.0")
            {
        QDomElement child = root.firstChildElement("category");
        while (!child.isNull())
        {
            parseCategoryElement(child,listCategory,listDescribe);
            child = child.nextSiblingElement("category");
        }
    }
}


void CKsPathManager::parseCategoryElement(const QDomElement &element,QList<QString> &listDescribe)
{
    QString szValue,szDescrible;

    QDomElement child = element.firstChildElement();
    while (!child.isNull())
    {
        if (child.tagName() == "module")
        {

            szValue = child.attribute("modulename");
            szDescrible = child.attribute("describe");
            listCategory.append(szValue);
            listDescribe.append(szDescrible);
        }
        child = child.nextSiblingElement();
    }
}

bool CKsPathManager::GetExecFilePath(QString &szPath)
{
    QString szRes;
    char dbPath[320];
    char *tmp = getenv(CKsPathManager::m_pMPS_HOME);
    szPath = "";

    if (tmp == 0)
    {
        return false;
    }

    strcpy(dbPath,tmp);
#ifdef Q_WS_WIN
    strcat(dbPath,"bin");
#else
    strcat(dbPath,"/bin");
#endif
    szPath += dbPath;

    return true;
}


    //
#ifdef Q_WS_WIN32
    szBinPath += exeName;
#else
    szBinPath = szBinPath +"/" + exeName;
#endif
    //
    szBinPath = szBinPath.trimmed();
    if( !QProcess::startDetached(szBinPath) )
    {
        QMessageBox::warning(0,tr("Job execute failed!"));
        return 2;
    }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读