Access violation in QXmlQuery



  • Hi
    I want to use QT in my MFC application in order to use Xpath. So I prepared this code in a method

    @
    QString method(){
    using namespace std;
    int argc=1;
    char *argv[]={"1","2"};

    QCoreApplication a(argc,argv);

    QFile sourceDocument;
    sourceDocument.setFileName(tablePath);
    if(!sourceDocument.open(QIODevice::ReadOnly)){
    //Can not open the file
    result=-1;
    QTimer::singleShot(1,&a,SLOT(quit()));
    return result;
    }

    QByteArray outArray;
    QBuffer buffer(&outArray);
    if(!buffer.open(QIODevice::ReadWrite)){
    //Can not open the file
    result=-1;
    QTimer::singleShot(1,&a,SLOT(quit()));
    return result;
    }

    QXmlQuery query(QXmlQuery::XQuery10);
    query.bindVariable("inputDocument", &sourceDocument);

    QString QueryString;
    //The rest of code
    }
    @

    If this method called two times consecutive, The first time every thing is OK and it successfully returned result set. But in the second call it breaks with access violation on line

    @QXmlQuery query(QXmlQuery::XQuery10);@

    what's up?



  • It seems it related to QCoreApplication. As I want to use QT in my MFC project and there is no Event loop before this method, I have to use QCoreApplication here.
    The problem is raised because QCoreApplication does not quit correctly. I use QTimer to do it like

    @QTimer::singleShot(1,&a,SLOT(quit()));@

    or

    @
    QTimer t
    t.connect (&t, SIGNAL(timeout()), &a, SLOT(quit()));
    t.start(1);
    @

    or

    @
    QCoreApplication::quit();
    @

    or
    @
    a.exit(0);
    @

    but none of them work. How should i stop qCoreApplication ?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.