[Qt-interest] Demo Browser and Qt::Concurrent query

Benjamin Meyer ben at meyerhome.net
Thu Jan 21 22:07:15 CET 2010


There was a number of spots in the demo browsers download window that had nothing to do with downloading that were using up the cpu (repainting when it wasn't necessary).  They have been changed in Arora.  I would suggest profiling your code to find (and fix) those problems.

-Benjamin Meyer

On Jan 20, 2010, at 12:27 AM, Nitin Mahajan wrote:

> Hello, 
> 
> I was trying the download functionality in demo browser. I am running Qt for Embedded Linux 4.5.3 on a ARM based board.
> 
> What I observe is that when I start the dowload of some file, the UI becomes very slow, meaning mouse cursor movement is jumpy.
> 
> To solve this I thought of seperating out the functionality in DownloadItem::downloadReadyRead() in a seperate thread. This I did using QtConcurrent::run().
> 
> This is how I did it, just moved the functionality from slot downloadReadyRead() to a fucntion named threadDownloadReadyRead() and passed this function to QtConcurrent::run(). 
> 
> The mouse movement is still jumpy though the file writing a happening in a seperate thread. 
> 
> Am I missing something while using QtConcurrent or that is not the right operation to be shifted to a new thread? Can I get some pointers towards this?
> 
> 
> 
> void DownloadItem::downloadReadyRead()
> {
> 	QFuture<void> future = QtConcurrent::run(this, &DownloadItem::threadDownloadReadyRead);
> }
> 
> void DownloadItem::threadDownloadReadyRead()
> {
> 	qint64 (QFile::*fn)(const QByteArray &byteArray) = &QFile::write;
> 	//printf("\nThread Id for download ready read is %x\n",(unsigned int) QThread::currentThread());	
> 	if (m_requestFileName && m_output.fileName().isEmpty())
>        return;
> 	if (m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() != 200)
> 		return;
>    if (!m_output.isOpen()) {
>        // in case someone else has already put a file there
>        if (!m_requestFileName)
>            getFileName();
>        if (!m_output.open(QIODevice::WriteOnly)) {
>            downloadInfoLabel->setText(tr("Error opening save file: %1")
>                    .arg(m_output.errorString()));
>            stopButton->click();
>            emit statusChanged();
>            return;
>        }
>        emit statusChanged();
>    }
> 	
> if (-1 == m_output.write(m_reply->readAll())) {
>        downloadInfoLabel->setText(tr("Error saving: %1")
>                .arg(m_output.errorString()));
>        stopButton->click();
>    }
> 	
> }
> 
> 
> regards
> 
> -Nitin
> 
> 
>      New Email names for you! 
> Get the Email name you&#39;ve always wanted on the new @ymail and @rocketmail. 
> Hurry before someone else does!
> http://mail.promotions.yahoo.com/newdomains/aa/
> 
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest





More information about the Qt-interest-old mailing list