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

Nitin Mahajan nitinm76 at yahoo.com
Wed Jan 20 06:27:42 CET 2010


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/




More information about the Qt-interest-old mailing list