Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Access violation in QXmlQuery
Forum Updated to NodeBB v4.3 + New Features

Access violation in QXmlQuery

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 795 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Paytam
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • P Offline
      P Offline
      Paytam
      wrote on last edited by
      #2

      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 ?

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved