Re: [SailfishDevel] QThread priority
On Wednesday 28 May 2014 22:07:20 Andrey Kozhevnikov wrote: need to look into your parseReadyData 28.05.2014 22:03, Krisztian Olah ?: Hi Andrey, 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. 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: void SomeClass::someMethod() { MyContainer* container = new MyContainer(); //reader has a handle to container, through which it populates the container MyXmlStreamReader* parser = new MyXmlStreamReader(container); QThread* parserThread = new QThread(); parser-moveToThread(parserThread); connect(parser, SIGNAL(finished()), this, SLOT(onParsingFinished) ); connect(parser, SIGNAL(finished()), parserThread, SLOT(quit()) ); connect(parser, SIGNAL(finished()), parser, SLOT(deleteLater()) ); connect(parserThread, SIGNAL(finished()), parserThread, SLOT(deleteLater()) ); parserThread-start(); reply = networkMngr-get(QNetworkRequest(someUrl)); //both pointers are class members connect(reply, SIGNAL(finished()), this, SLOT(onAllDataRecieved()) ); //this starts the parser with the data available at the time, // when parser reaches the end of xml document it emits itsfinished() signal connect(reply, SIGNAL(readyRead()), this, SLOT(parseReadyData()) ); } To run parser in parallel just to get results in the main thread it is better to use QtConcurrent::run() + QFutureWatcher. - denis Thanks again Kris On 28 May 2014 06:16, Andrey Kozhevnikov coderusin...@gmail.com mailto:coderusin...@gmail.com wrote: it can't doesn't help much. you initializing thread wrong. simple threading way is: MyXmlParser *parser = new MyXmlParser(xmlDocument); QThread *thread = new QThread(parser); parser-moveToThread(thread); QObject::connect(thread, SIGNAL(started()), parser, SLOT(parse())); QObject::connect(parser, SIGNAL(parseComplete(QVariantMap)), this, SLOT(onParseComplete(QVariantMap))); thread-start(); 28.05.2014 03:24, Krisztian Olah ?: Hi list, 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? Thanks Kris ___ SailfishOS.org Devel mailing list To unsubscribe, please send a mail todevel-unsubscr...@lists.sailfishos.org mailto:devel-unsubscr...@lists.sailfishos.org ___ SailfishOS.org Devel mailing list To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org mailto:devel-unsubscr...@lists.sailfishos.org ___ SailfishOS.org Devel mailing list To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org ___ SailfishOS.org Devel mailing list To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org
Re: [SailfishDevel] QThread priority
Thanks Denis, I'll look into QtConcurrent + QFutureWatcher tonight when I'll have time. I will also consult pthread's documentation after comparing the two approaches. Thanks again Kris On 29 May 2014 11:01, Denis Zalevskiy denis.zalevs...@jollamobile.com wrote: On Thursday 29 May 2014 13:55:40 Denis Zalevskiy wrote: To run parser in parallel just to get results in the main thread it is better to use QtConcurrent::run() + QFutureWatcher. Also, to set priority I guess you can use posix pthread functions, smth. like ::pthread_setschedprio(::pthread_self(), SCHED_IDLE); - denis - denis Thanks again Kris On 28 May 2014 06:16, Andrey Kozhevnikov coderusin...@gmail.com mailto:coderusin...@gmail.com wrote: it can't doesn't help much. you initializing thread wrong. simple threading way is: MyXmlParser *parser = new MyXmlParser(xmlDocument); QThread *thread = new QThread(parser); parser-moveToThread(thread); QObject::connect(thread, SIGNAL(started()), parser, SLOT(parse())); QObject::connect(parser, SIGNAL(parseComplete(QVariantMap)), this, SLOT(onParseComplete(QVariantMap))); thread-start(); 28.05.2014 03:24, Krisztian Olah ?: Hi list, 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? Thanks Kris ___ SailfishOS.org Devel mailing list To unsubscribe, please send a mail todevel-unsubscr...@lists.sailfishos.org mailto:devel-unsubscr...@lists.sailfishos.org ___ SailfishOS.org Devel mailing list To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org mailto:devel-unsubscr...@lists.sailfishos.org ___ SailfishOS.org Devel mailing list To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org ___ SailfishOS.org Devel mailing list To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org ___ SailfishOS.org Devel mailing list To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org ___ SailfishOS.org Devel mailing list To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org
Re: [SailfishDevel] QThread priority
Andrey, you are right if I'm not using the signals/slots, but calling it directly causes it to run in current thread. It works just fine now, thanks. Denis, I did check out QtConcurrent::run(), but since I return void from the function and I have to call the function multiple times possibly in the same thread so that I can append to QXmlStreamReader's data, I think it is easier to just use QThread in this case. However thank you for your input, I'm sure I will make use of QtConcurrent in the QFuture. (pun intended) ;) On 29 May 2014 12:23, Krisztian Olah fasza2mob...@gmail.com wrote: Thanks Denis, I'll look into QtConcurrent + QFutureWatcher tonight when I'll have time. I will also consult pthread's documentation after comparing the two approaches. Thanks again Kris On 29 May 2014 11:01, Denis Zalevskiy denis.zalevs...@jollamobile.com wrote: On Thursday 29 May 2014 13:55:40 Denis Zalevskiy wrote: To run parser in parallel just to get results in the main thread it is better to use QtConcurrent::run() + QFutureWatcher. Also, to set priority I guess you can use posix pthread functions, smth. like ::pthread_setschedprio(::pthread_self(), SCHED_IDLE); - denis - denis Thanks again Kris On 28 May 2014 06:16, Andrey Kozhevnikov coderusin...@gmail.com mailto:coderusin...@gmail.com wrote: it can't doesn't help much. you initializing thread wrong. simple threading way is: MyXmlParser *parser = new MyXmlParser(xmlDocument); QThread *thread = new QThread(parser); parser-moveToThread(thread); QObject::connect(thread, SIGNAL(started()), parser, SLOT(parse())); QObject::connect(parser, SIGNAL(parseComplete(QVariantMap)), this, SLOT(onParseComplete(QVariantMap))); thread-start(); 28.05.2014 03:24, Krisztian Olah ?: Hi list, 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? Thanks Kris ___ SailfishOS.org Devel mailing list To unsubscribe, please send a mail todevel-unsubscr...@lists.sailfishos.org mailto:devel-unsubscr...@lists.sailfishos.org ___ SailfishOS.org Devel mailing list To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org mailto:devel-unsubscr...@lists.sailfishos.org ___ SailfishOS.org Devel mailing list To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org ___ SailfishOS.org Devel mailing list To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org ___ SailfishOS.org Devel mailing list To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org ___ SailfishOS.org Devel mailing list To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org
Re: [SailfishDevel] QThread priority
it can't doesn't help much. you initializing thread wrong. simple threading way is: MyXmlParser *parser = new MyXmlParser(xmlDocument); QThread *thread = new QThread(parser); parser-moveToThread(thread); QObject::connect(thread, SIGNAL(started()), parser, SLOT(parse())); QObject::connect(parser, SIGNAL(parseComplete(QVariantMap)), this, SLOT(onParseComplete(QVariantMap))); thread-start(); 28.05.2014 03:24, Krisztian Olah ?: Hi list, 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? Thanks Kris ___ SailfishOS.org Devel mailing list To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org ___ SailfishOS.org Devel mailing list To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org
Re: [SailfishDevel] QThread priority
Hi Andrey, 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. 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: void SomeClass::someMethod() { MyContainer* container = new MyContainer(); //reader has a handle to container, through which it populates the container MyXmlStreamReader* parser = new MyXmlStreamReader(container); QThread* parserThread = new QThread(); parser-moveToThread(parserThread); connect(parser, SIGNAL(finished()), this, SLOT(onParsingFinished) ); connect(parser, SIGNAL(finished()), parserThread, SLOT(quit()) ); connect(parser, SIGNAL(finished()), parser, SLOT(deleteLater()) ); connect(parserThread, SIGNAL(finished()), parserThread, SLOT(deleteLater()) ); parserThread-start(); reply = networkMngr-get(QNetworkRequest(someUrl)); //both pointers are class members connect(reply, SIGNAL(finished()), this, SLOT(onAllDataRecieved()) ); //this starts the parser with the data available at the time, // when parser reaches the end of xml document it emits its finished() signal connect(reply, SIGNAL(readyRead()), this, SLOT(parseReadyData()) ); } Thanks again Kris On 28 May 2014 06:16, Andrey Kozhevnikov coderusin...@gmail.com wrote: it can't doesn't help much. you initializing thread wrong. simple threading way is: MyXmlParser *parser = new MyXmlParser(xmlDocument); QThread *thread = new QThread(parser); parser-moveToThread(thread); QObject::connect(thread, SIGNAL(started()), parser, SLOT(parse())); QObject::connect(parser, SIGNAL(parseComplete(QVariantMap)), this, SLOT(onParseComplete(QVariantMap))); thread-start(); 28.05.2014 03:24, Krisztian Olah пишет: Hi list, 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? Thanks Kris ___ SailfishOS.org Devel mailing list To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org ___ SailfishOS.org Devel mailing list To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org ___ SailfishOS.org Devel mailing list To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org
Re: [SailfishDevel] QThread priority
need to look into your parseReadyData 28.05.2014 22:03, Krisztian Olah ?: Hi Andrey, 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. 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: void SomeClass::someMethod() { MyContainer* container = new MyContainer(); //reader has a handle to container, through which it populates the container MyXmlStreamReader* parser = new MyXmlStreamReader(container); QThread* parserThread = new QThread(); parser-moveToThread(parserThread); connect(parser, SIGNAL(finished()), this, SLOT(onParsingFinished) ); connect(parser, SIGNAL(finished()), parserThread, SLOT(quit()) ); connect(parser, SIGNAL(finished()), parser, SLOT(deleteLater()) ); connect(parserThread, SIGNAL(finished()), parserThread, SLOT(deleteLater()) ); parserThread-start(); reply = networkMngr-get(QNetworkRequest(someUrl)); //both pointers are class members connect(reply, SIGNAL(finished()), this, SLOT(onAllDataRecieved()) ); //this starts the parser with the data available at the time, // when parser reaches the end of xml document it emits itsfinished() signal connect(reply, SIGNAL(readyRead()), this, SLOT(parseReadyData()) ); } Thanks again Kris On 28 May 2014 06:16, Andrey Kozhevnikov coderusin...@gmail.com mailto:coderusin...@gmail.com wrote: it can't doesn't help much. you initializing thread wrong. simple threading way is: MyXmlParser *parser = new MyXmlParser(xmlDocument); QThread *thread = new QThread(parser); parser-moveToThread(thread); QObject::connect(thread, SIGNAL(started()), parser, SLOT(parse())); QObject::connect(parser, SIGNAL(parseComplete(QVariantMap)), this, SLOT(onParseComplete(QVariantMap))); thread-start(); 28.05.2014 03:24, Krisztian Olah ?: Hi list, 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? Thanks Kris ___ SailfishOS.org Devel mailing list To unsubscribe, please send a mail todevel-unsubscr...@lists.sailfishos.org mailto:devel-unsubscr...@lists.sailfishos.org ___ SailfishOS.org Devel mailing list To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org mailto:devel-unsubscr...@lists.sailfishos.org ___ SailfishOS.org Devel mailing list To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org ___ SailfishOS.org Devel mailing list To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org
Re: [SailfishDevel] QThread priority
I see, I'll give it a go and get back with the result. Thanks for your help Andrey Kris On Wed May 28 2014 19:38:35 GMT+0100 (BST), Andrey Kozhevnikov wrote: you can't do it. you should call it with slot only, else it will be called in current thread, not one you created. 28.05.2014 23:07, Krisztian Olah ?: it just calls: //pointer also a member parser-addData() parser-parse() although it is a bit messy, here is my parser class and its methods: //header: #include QObject #include QXmlStreamReader #include QSharedPointer #include disruption.h #include street.h #include trafficcontainer.h class TrafficXmlReader : public QObject { Q_OBJECT public: TrafficXmlReader(QObject* parent = 0); private: //TrafficContainer has a QListDisruption and a QHashint,Street member // and it interacts with 2 corresponding models for each contained container QSharedPointerTrafficContainer container; int count; int currentID; Disruption currentDisruption;//just a struct containing the strings Street currentStreet;//just a struct containing the strings bool inDisruption; bool inPoint; bool inStreet; QXmlStreamReader reader; public: void setContainer(QSharedPointerTrafficContainer); void setDevice(QIODevice*); signals: void finished(); void partFinished(); public slots: void addData(const QByteArray); void parse(); }; #endif // TRAFFICXMLREADER_H //implementation: #include trafficxmlreader.h #include QDebug #include QRegExp #include trafficcontainer.h TrafficXmlReader::TrafficXmlReader(QObject* c) : container(static_castTrafficContainer*(c)), count(0), currentID(0), inDisruption(false), inPoint(false), inStreet(false) { reader.setNamespaceProcessing(false); } void TrafficXmlReader::setContainer(QSharedPointerTrafficContainer newContainer) { container.clear(); container = newContainer; } void TrafficXmlReader::setDevice(QIODevice* device) { reader.setDevice(device); } //public slots: void TrafficXmlReader::addData(const QByteArray data) { reader.addData(data); } void TrafficXmlReader::parse() { while (!reader.atEnd()) { reader.readNext(); ++count; if (reader.qualifiedName() == Disruption) { if (reader.isStartElement()) { inDisruption = true; currentID = reader.attributes().value(id).toInt(); } else if (reader.isEndElement()) { currentDisruption.id = currentID; currentID = 0; container.data()-addDisruption(currentDisruption); inDisruption = false; } } else if (inDisruptionreader.qualifiedName() == status) { currentDisruption.status = reader.readElementText(); } else if (inDisruptionreader.qualifiedName() == severity) { currentDisruption.severity = reader.readElementText(); } else if (inDisruptionreader.qualifiedName() == levelOfInterest) { currentDisruption.levelOfInterest = reader.readElementText(); } else if (inDisruptionreader.qualifiedName() == category) { currentDisruption.category = reader.readElementText(); } else if (inDisruptionreader.qualifiedName() == subCategory) { currentDisruption.subCategory = reader.readElementText(); } else if (inDisruptionreader.qualifiedName() == startTime) { currentDisruption.startTime = reader.readElementText(); } //replace ',' with ,if not followed by a whitespace, happends many times due to lousy typing //it is to make WordWrap possible in gui else if (inDisruptionreader.qualifiedName() == location) { QString location = reader.readElementText(); int i; while ((i = location.indexOf(QRegExp(,[^\\s-]))) != -1 ) { location = location.insert(++i,); } currentDisruption.location = location; } else if (inDisruption
[SailfishDevel] QThread priority
Hi list, 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? Thanks Kris ___ SailfishOS.org Devel mailing list To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org