通过读取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("Warning"), tr("Job execute failed!"));
       	 	return 2;
    	}
} else { QMessageBox::warning(0, tr("Warning"), 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> &listCategory,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("Warning"), tr("Job execute failed!"));
        return 2;
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值