<div dir="ltr">Hi Andrey,<div> Thanks for the answer, your snippet looks very similar to what I have. Perhaps if I posted my code segment would be of help in helping me figuring out where I'm wrong. <br><div style> During parsing CPU usage reaches 97-100% which causes my GUI to hang(I have about 500 000 opening and closing tags and half of the enclosed items I need to process: save, in some cases insert spaces, etc), especially awkward when I start parsing whilst still fetching the data from network(sometimes hangs during pageStack.push() ), but it's bad for up to 2-5 seconds nevertheless. I wouldn't mind if parsing took 10 seconds if GUI was responsive. This is what I'm doing:</div>
<div style><br></div><div style>void SomeClass::someMethod() {</div><div style> MyContainer* container = new MyContainer();</div><div style> //reader has a handle to container, through which it populates the container</div>
<div style> MyXmlStreamReader* parser = new MyXmlStreamReader(container);</div><div style> QThread* parserThread = new QThread();</div><div style> parser->moveToThread(parserThread);</div>
<div style>
<pre style="margin-top:0px;margin-bottom:0px"><br></pre>
<pre style="margin-top:0px;margin-bottom:0px"> connect(parser, SIGNAL(finished()), this, SLOT(onParsingFinished) );</pre><pre style="margin-top:0px;margin-bottom:0px"> connect(parser, SIGNAL(finished()), parserThread, SLOT(quit()) );</pre>
<pre style="margin-top:0px;margin-bottom:0px"> connect(parser, SIGNAL(finished()), parser, SLOT(deleteLater()) );</pre><pre style="margin-top:0px;margin-bottom:0px"> connect(parserThread, SIGNAL(finished()), parserThread, SLOT(deleteLater()) );</pre>
<pre style="margin-top:0px;margin-bottom:0px"><br></pre><pre style="margin-top:0px;margin-bottom:0px"> parserThread->start();</pre>
<pre style="margin-top:0px;margin-bottom:0px"><br></pre><pre style="margin-top:0px;margin-bottom:0px"> reply = networkMngr->get(QNetworkRequest(someUrl)); //both pointers are class members</pre><pre style="margin-top:0px;margin-bottom:0px">
<br></pre><pre style="margin-top:0px;margin-bottom:0px"> connect(reply, SIGNAL(finished()), this, SLOT(onAllDataRecieved()) );</pre><pre style="margin-top:0px;margin-bottom:0px"><br></pre><pre style="margin-top:0px;margin-bottom:0px">
<span style="font-family:arial">//this starts the parser with the data available at the time, </span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="font-family:arial"> // when parser reaches the end of xml document it emits its </span><span style="font-family:arial">finished() signal</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"> connect(reply, SIGNAL(readyRead()), this, SLOT(parseReadyData()) );</pre><pre style="margin-top:0px;margin-bottom:0px"></pre><pre style="margin-top:0px;margin-bottom:0px">
<span style="color:rgb(0,0,0)">}</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(0,0,0)"><br></span></pre><pre style="margin-top:0px;margin-bottom:0px">Thanks again</pre><pre style="margin-top:0px;margin-bottom:0px">
Kris</pre></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 28 May 2014 06:16, Andrey Kozhevnikov <span dir="ltr"><<a href="mailto:coderusinbox@gmail.com" target="_blank">coderusinbox@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">
it can't "doesn't help much". you initializing thread wrong.<br>
<br>
simple threading way is:<br>
<br>
<tt>MyXmlParser *parser = new MyXmlParser(xmlDocument);</tt><tt><br>
</tt><tt>QThread *thread = new QThread(parser);</tt><tt><br>
</tt><tt>parser->moveToThread(thread);</tt><tt><br>
</tt><tt>QObject::connect(thread, SIGNAL(started()), parser,
SLOT(parse()));</tt><tt><br>
</tt><tt>QObject::connect(parser, SIGNAL(parseComplete(QVariantMap)</tt><tt>),
this, SLOT(onParseComplete(QVariantMap)));</tt><tt><br>
</tt><tt>thread->start();</tt><br>
<br>
<div>28.05.2014 03:24, Krisztian Olah пишет:<br>
</div>
<blockquote type="cite"><div><div class="h5">
<div dir="ltr"> Hi list,
<div> I have a rather large xml file to parse and it
causes the UI to freeze, I assingned the parser to a different
thread, but it doesn't help much. According to the Qt
documentation QThread::setPriority() doesn't work on Linux, is
there some kind of workaround that could be used?</div>
<div><br>
</div>
<div>Thanks</div>
<div>Kris</div>
</div>
<br>
<fieldset></fieldset>
<br>
</div></div><pre>_______________________________________________
SailfishOS.org Devel mailing list
To unsubscribe, please send a mail to <a href="mailto:devel-unsubscribe@lists.sailfishos.org" target="_blank">devel-unsubscribe@lists.sailfishos.org</a></pre>
</blockquote>
<br>
</div>
<br>_______________________________________________<br>
SailfishOS.org Devel mailing list<br>
To unsubscribe, please send a mail to <a href="mailto:devel-unsubscribe@lists.sailfishos.org">devel-unsubscribe@lists.sailfishos.org</a><br></blockquote></div><br></div>