我想在我的MFC DLL中使用QT XML。我想使用它来使QXmlQuery选择我的xml文件中的节点。 我创建了这样的标题。问题是如果我在for循环中调用select方法,程序会因为访问冲突而在第二次迭代中崩溃。问题出现是因为QCoreApplication没有正确退出。我该怎么办
#define NOMINMAX
#pragma once
#include <windows.h>
#include <vector>
#include <iostream>
#include <string>
#include <QtCore/QObject>
#include <QtCore/QFile>
#include <QtXml/QDomDocument>
#include <QtXml/QDomElement>
#include <QtCore/QCoreApplication>
#include <QtXmlPatterns/QXmlQuery>
#include <QtCore/QBuffer>
#include <QtXmlPatterns/QXmlSerializer>
#include <QtCore/QTimer>
#include <QtWidgets/QApplication>
#include "Utilities.h"
#include "GeneralConfigs.h"
namespace DBMS_ENGINE{
class SelectEngine: public QObject
{
Q_OBJECT
public:
explicit SelectEngine();
DWORD DBMS_ENGINE::SelectEngine::Select(QString tablePath){
DWORD result=0;
using namespace std;
int argc=1;
char *argv[]={"1","2"};
QTimer t;
a=new QCoreApplication(argc,argv);
connect(a,SIGNAL(a->aboutToQuit()),a,SLOT(quit()));
QFile sourceDocument;
sourceDocument.setFileName(tablePath);
sourceDocument.open(QIODevice::ReadOnly);
QByteArray outArray;
QBuffer buffer(&outArray);
buffer.open(QIODevice::ReadWrite);
QXmlQuery query;
query.bindVariable("inputDocument", &sourceDocument);
QString QueryString;
QueryString=QString("declare variable $inputDocument external; \n doc($inputDocument)/root/key");
query.setQuery(QueryString);
QString result1;
query.evaluateTo(&result1);
}//end of methos
private:
QCoreApplication *a;
private slots:
void quit(){
QCoreApplication::quit();
a->exit();
qApp->quit();
QCoreApplication::exit();
}//end of method
};//end of class
}//end of namespace