Important: Please read the Qt Code of Conduct -

Retrieving data from XML file via XQuery slowing down Qt application?

  • Hey,

    I have recently added a function to my application that lets it query an XML file via XQuery to get some data. This function is automatically executed when the app launches. Ever since I added in this function, my application takes an annoyingly long time to launch, sometimes up to 20 secs. Before I added this function it launched very quickly. I am fairly certain that this function is the offender. Does calling an XQuery file to query an XML file and return the results really slow down applications this much? I plan to be using a lot of XML/XQuery in conjunction with Qt in the future and it would be nice to not have to wait half a minute for an app to launch. I know querying anything will take some time, but Im just querying a small, local XML file so I don't see why it should take so long. Any ideas on how to speed it up?


  • Is putting the file parsing in another thread an option ? At least it will not slow down the GUI. But have to agree with you that something seems wrong for it to take 20 seconds. Why don't you post the code so we can take a look at it, might be something obvious

  • the file parsing is related to the GUI because its retrieving text to place in QToolButtons.
    Heres the code:
    @void sideBar::initializeSideBar()
    QXmlQuery query1;
    QString name1;
    QString url1;
    QXmlQuery query2;
    QString name2;
    QString url2;
    QFile sidebarQuery("/Users/nick/Desktop/files for NovaBrowser/sidebarQuery.xq");;
    query1.setQuery(&sidebarQuery, QUrl::fromLocalFile(sidebarQuery.fileName()));


    @xquery version "1.0";

    doc("sidebarApps.xml")/sidebarapps/app[pos = 1]/name@

    @<?xml version="1.0" encoding="UTF-8"?>

    <name>Google Drive</name>


    <name>Google Docs</name>

    <name>Google Calendar</name>



    Ok so there you have it. It probably is something obvious (Im still a n00bie). Is it possible to do the file parsing in another thread and then send the results into the GUI thread?
    Thanks for your help!

  • why do you not use signal and slot mechanism?

    see "QThread Basics":

  • why would I use signals and slots?

  • for sending the results from the parserthread to the GUI

  • So I would make a thread to parse the XML and another for the GUI. Once the parsing is complete, it would send the results to the GUI?
    How would that work? Could you give me a code example?

  • So can I place an individual function in a QThread rather than the entire class? I would like to create a new thread, run the XML parsing function in it, then send the data to the GUI thread via signals and slots, and finally destroy the thread. Is that possible? how would I do it?

Log in to reply