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?
Thanks!
-
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:
C++:
@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");sidebarQuery.open(QIODevice::ReadWrite); query1.setQuery(&sidebarQuery, QUrl::fromLocalFile(sidebarQuery.fileName())); query1.evaluateTo(&name1); createAppButton(name1);
}
@XQuery:
@xquery version "1.0";doc("sidebarApps.xml")/sidebarapps/app[pos = 1]/name@
XML:
@<?xml version="1.0" encoding="UTF-8"?><sidebarapps>
<app>
<name>Google Drive</name>
<url></url>
<pos>1</pos>
</app><app>
<name>Gmail</name>
<url></url>
<pos>2</pos>
</app><app>
<name>Google Docs</name>
<url></url>
<pos>3</pos>
</app><app>
<name>Google Calendar</name>
<url></url>
<pos>4</pos>
</app><app>
<name>Facebook</name>
<url></url>
<pos>5</pos>
</app><app>
<name>Twitter</name>
<url></url>
<pos>6</pos>
</app>
</sidebarapps>@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?