[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    KIO::NetAcces & Multithreading? (for plasma)
From:       Mercurio <mercurio () personellarete ! it>
Date:       2007-09-28 11:27:34
Message-ID: 46FCE526.9010705 () personellarete ! it
[Download RAW message or body]

Hi,
I need to asynchronously load an image and scale it for the Picture
Frame  plasmoid. (at this moment it hangs the whole plasma when it does
these operations!). After a bit of research, I chose to use QThread and
use a very simple solution.
Here is the relevant part of my derived class:
(at present it lacks of protection from an unlikely race condition that
occurs when the user asks to load another image before the other is loaded)

void LoadImageThread::startLoadingImage(KUrl url, int maxDimension){
    m_url = url;
    m_maxDimension = maxDimension;
    start();
}

void LoadImageThread::run()
{
    QImage myPicture;
    QString tmpFile;
    if ( !KIO::NetAccess::download( m_url, tmpFile, 0L ) )
    {
        kDebug() << "Load Error!\n";
   
    } else {
          QImage tempImage(tmpFile);
          //[here some processing]
          myPicture=tempImage;
    }
    //[here create another image if myPicture is null]
   
    emit imageLoaded(myPicture);
 }

It works perfectly, but when I create more than one instance of the
applet, I get the error "QObject::startTimer: QTimer can only be used
with threads started with QThread", and only the first applet can load
the images. (even if I don't explicitly use QTimer in the plasmoid).

If I load the image from a local file without using KIO::NetAcces I have
no problem.

I've already refactored the code using KIO::Job, but I gaved up
asynchronous image processing... so if someone know a simple solution
for this problem I'd prefer to use the multi-threading approach ^^''.

- Antonio Vinci
 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic