Retrieving data from XML file via XQuery slowing down Qt application?
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:
QFile sidebarQuery("/Users/nick/Desktop/files for NovaBrowser/sidebarQuery.xq");
sidebarQuery.open(QIODevice::ReadWrite); query1.setQuery(&sidebarQuery, QUrl::fromLocalFile(sidebarQuery.fileName())); query1.evaluateTo(&name1); createAppButton(name1);
@xquery version "1.0";
doc("sidebarApps.xml")/sidebarapps/app[pos = 1]/name@
@<?xml version="1.0" encoding="UTF-8"?>
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":http://qt-project.org/doc/qt-5.0/qtcore/thread-basics.html
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?