×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    36

    Exclamation QT Resource load too slow at start up and not be able to load from QThread::run

    I have a problem:
    I use some image in qt resource (.qrc file) but application load resource too slow at startup. (user have to wait about 1 minute or more)


    So, I try to load resource in another thread using QThread.
    But in QThread::run, it can not load resource correctly.

    Here is my code:
    I call StartT to start the loading resource thread.


    #ifndef SPLASHFORM_H
    #define SPLASHFORM_H

    #include "ui_SplashForm.h"

    class SplashForm : public QDialog, private Ui::SplashForm {
    Q_OBJECT
    public:
    SplashForm(QWidget *parent = 0);
    public slots:
    void OnThreadFinished();
    void StartT();
    protected:
    void changeEvent(QEvent *e);
    };

    #endif // SPLASHFORM_H



    #include "SplashForm.h"
    #include <QThread>
    #include <QFile>
    #include <QMessageBox>
    //#include <iostream>
    //using namespace std;
    class LoadResourceThreadublic QThread
    {
    public:
    LoadResourceThread(QObject* aParent):QThread(aParent),iSize(-10),aRunned(false) {};
    int iSize;
    bool aRunned;
    protected:
    virtual void run()
    {

    //QFile aFile(QString::fromUtf8(":/images/ttlogo16x16.png"));
    //iSize = aFile.readAll().size();
    QPixmap aPxm(QString::fromUtf8(":/images/ttlogo16x16.png")) ;
    iSize = aPxm.height();//aFile.readAll().size();
    aRunned = true;
    //cout<<iSize<<" from run";

    // QIcon icon;
    // icon.addFile(QString::fromUtf8(":/images/ttlogo16x16.png"), QSize(), QIcon::Normal, QIcon::Off);
    // if (icon.pixmap(20,20).height() > 0)
    // QMessageBox::information(NULL , "Load finished" , "Icon OK Finished" );
    // else
    // QMessageBox::information(NULL , "Load finished" , "Icon not ok Finished" );
    }

    };

    SplashForm::SplashForm(QWidget *parent) :
    QDialog(parent){
    setupUi(this);

    }

    void SplashForm::StartT()
    {
    // QPixmap aPxm(QString::fromUtf8(":/images/ttlogo16x16.png")) ;
    // int iSize = aPxm.height();//aFile.readAll().size();
    // if (iSize)
    // QMessageBox::information(this , "Load finished" , "StartT Finished ok" );
    //

    LoadResourceThread* aLoadResourceThread = new LoadResourceThread(this);
    connect(aLoadResourceThread , SIGNAL(finished()) , this , SLOT( OnThreadFinished() ) );
    aLoadResourceThread->start();
    }
    void SplashForm::changeEvent(QEvent *e)
    {
    QWidget::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
    retranslateUi(this);
    break;
    default:
    break;
    }
    }

    void SplashForm::OnThreadFinished()
    {
    LoadResourceThread* aThread = dynamic_cast<LoadResourceThread*>(sender() );
    if (aThread && aThread->aRunned)
    {
    if (aThread->iSize > 0)
    QMessageBox::information(this , "Load finished" , "Finished ok" + QString::number(aThread->iSize ) );
    else
    QMessageBox::information(this , "Load finished" , "Finished not ok"+QString::number(aThread->iSize ) );

    }
    this->accept();
    }


    Please help me how to solve this problem
    thanks in advance.

  2. #2
    Registered User
    Join Date
    Mar 2005
    Posts
    36

    Re: QT Resource load too slow at start up and not be able to load from QThread::run

    I try it in QT for PC then it is OK but when build in symbian it always fail to load resource from new thread.

  3. #3
    Regular Contributor
    Join Date
    Mar 2009
    Posts
    430

    Re: QT Resource load too slow at start up and not be able to load from QThread::run

    Qt resources are implemented using a static char* array that contains the resource data. These data gets compiled into your application executable. It will make the application size bigger. I read somewhere else that static data is somehow bad on symbian and should be avoided. You could either try to load the files from filesystem or use http://wiki.forum.nokia.com/index.ph...rce_Access_API to access a native symbian resource file.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×