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

前端之家收集整理的这篇文章主要介绍了通过读取xml文件存储的可执行文件描述符,获取可执行文件名称,并启动可执行文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  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;
    }

猜你在找的XML相关文章