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

前端之家收集整理的这篇文章主要介绍了通过读取xml文件存储的可执行文件描述符,获取可执行文件名称,并启动可执行文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. m_mvaAnalysisAction = new QAction(tr("mva Analysis"),this);
  2. connect(m_mvaAnalysisAction,SIGNAL(triggered()),this,SLOT(parallelSlot()));
  3. m_parallelActions->addAction(m_mvaAnalysisAction);
  1.  
  1. int CKsMPSActions::parallelSlot()
  2. {
  3. // 获得XML文件,Bin文件根目录
  4. QString sXMLPathName,szBinPath;
  5. QString exeName;//可执行文件
  6. QList <QString> exeStrList,describeList;//可执行文件列表,可执行文件相对应的描述符列表
  7. if (!CKsPathManager::GetVelocityXMLPath(sXMLPathName))
  8. return -1;
  9.  
  10. // 读XML文件,获得bin文件夹下的可执行文件列表,可执行文件相对应的描述符列表
  11. CKsPathManager::InitCategroy(sXMLPathName,exeStrList,describeList);
  12.  
  13. // 规避无效值
  14. int iCount = exeStrList.size();
  15. if (iCount == 0)
  16. {
  17. QMessageBox::warning(0,tr("Warning"),tr("Job execute Failed!"));
  18. return 1;
  19. }
  20.  
  21. //可执行文件所在的根目录,即bin目录
  22. if( !CKsPathManager::GetExecFilePath(szBinPath))
  23. return -1;
  24. //
  25. if(describeList.contains(tr("mva Analysis")))
  26. {
  27. exeName = exeStrList.at(describeList.indexOf(tr("mva Analysis")));
  28.  
  29.     //
  30. #ifdef Q_WS_WIN32
  31.     	szBinPath += exeName;
  32. #else
  33.     	szBinPath = szBinPath +"/" + exeName;
  34. #endif
  35.     	//
  36.     	szBinPath = szBinPath.trimmed();
  37.     	if( !QProcess::startDetached(szBinPath) )
  38.    	{
  39.         	QMessageBox::warning(0,tr("Job execute Failed!"));
  40.        	 	return 2;
  41.     	}
    } else { QMessageBox::warning(0,tr("Job execute Failed!")); return 1; } return 0;}

  42.  
  43. char *CKsPathManager::m_pVelocityInitFile = "velocity.xml";
  44. // 获得速度XML文件路径
  45. bool CKsPathManager::GetVelocityXMLPath(QString& sXMLPath)
  46. {
  47.     QString sLocTemp;
  48.     if (GetModuleInitPath(sLocTemp) == false)
  49.         return false;
  50.     sXMLPath += sLocTemp;
  51.     sXMLPath += CKsPathManager::m_pVelocityInitFile;
  52.     return true;
  53. }


  54.  
  55. void CKsPathManager::InitCategroy(QString szFileName,QList<QString> &listCategory,QList<QString> &listDescribe)
  56. {
  57.     QFile file(szFileName);
  58.     QDomDocument domDocument;
  59.     QString errorStr;
  60.     int errorLine;
  61.     int errorColumn;
  62.     //设置QFile
  63.     if (!domDocument.setContent((QIODevice  *)&file,true,&errorStr,&errorLine,&errorColumn)) {
  64.         return;
  65.     }
  66.     QDomElement root = domDocument.documentElement();
  67.     if (root.tagName() == "xml")
  68.         if (root.hasAttribute("version")
  69.             && root.attribute("version") == "1.0")
  70.             {
  71.         QDomElement child = root.firstChildElement("category");
  72.         while (!child.isNull())
  73.         {
  74.             parseCategoryElement(child,listCategory,listDescribe);
  75.             child = child.nextSiblingElement("category");
  76.         }
  77.     }
  78. }
  79. void CKsPathManager::parseCategoryElement(const QDomElement &element,QList<QString> &listDescribe)
  80. {
  81.     QString szValue,szDescrible;
  82.     QDomElement child = element.firstChildElement();
  83.     while (!child.isNull())
  84.     {
  85.         if (child.tagName() == "module")
  86.         {
  87.             szValue = child.attribute("modulename");
  88.             szDescrible = child.attribute("describe");
  89.             listCategory.append(szValue);
  90.             listDescribe.append(szDescrible);
  91.         }
  92.         child = child.nextSiblingElement();
  93.     }
  94. }

  95. bool CKsPathManager::GetExecFilePath(QString &szPath)
  96. {
  97.     QString szRes;
  98.     char dbPath[320];
  99.     char *tmp = getenv(CKsPathManager::m_pMPS_HOME);
  100.     szPath = "";
  101.     if (tmp == 0)
  102.     {
  103.         return false;
  104.     }
  105.     strcpy(dbPath,tmp);
  106. #ifdef Q_WS_WIN
  107.     strcat(dbPath,"\\bin\\");
  108. #else
  109.     strcat(dbPath,"/bin");
  110. #endif
  111.     szPath += dbPath;
  112.     return true;
  113. }


  114.  
  115.  
  116.     //
  117. #ifdef Q_WS_WIN32
  118.     szBinPath += exeName;
  119. #else
  120.     szBinPath = szBinPath +"/" + exeName;
  121. #endif
  122.     //
  123.     szBinPath = szBinPath.trimmed();
  124.     if( !QProcess::startDetached(szBinPath) )
  125.     {
  126.         QMessageBox::warning(0,tr("Job execute Failed!"));
  127.         return 2;
  128.     }

猜你在找的XML相关文章