×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Jun 2012
    Posts
    105

    Post QT QDeclarativeImageProvider child class single instance?

    Hi,
    has someone else seen this?
    I have a

    class QMyImgProvClass : public QDeclarativeImageProvider{
    ..
    virtual QImage requestImage(const QString &id, QSize *size, const QSize& requestedSize){
    ...
    }
    QMyImgProvClass * instance(){
    static QMyImgProvClass s_myClass;
    return &s_myClass;
    }
    public:
    QList<int> m_list;
    };

    Since I need to use this in a plugin, I register it in the

    void BookmarkModelPluginPlugin::initializeEngine(QDeclarativeEngine *engine, const char *uri){
    engine->addImageProvider(QLatin1String(MY_IMGPROV_NAME), QMyImgProvClass::Instance());
    }

    through a simple Singleton.

    In the plugin then, I populate the m_list;
    .
    Now, the requestImage is called correctly from QML. BUT, the effect is that the m_list list is EMPTY for each call. It seems that for each call to the requestImage, the "this" pointer is different.

    I thought the addImageProvider registers a single object as an image provider?
    Last edited by tkastlunger; 2012-08-24 at 07:03.

  2. #2
    Nokia Developer Expert
    Join Date
    Jun 2012
    Posts
    55

    Re: QT QDeclarativeImageProvider child class single instance?

    Are you populating m_list before opening any QML file?

    Br,
    Villep

  3. #3
    Registered User
    Join Date
    Jun 2012
    Posts
    105

    Re: QT QDeclarativeImageProvider child class single instance?

    From inside ::componentComplete of the plugin.

  4. #4
    Nokia Developer Expert
    Join Date
    Jun 2012
    Posts
    55

    Re: QT QDeclarativeImageProvider child class single instance?

    What ::componentComplete are you referring to? Component.onCompleted inside QML? How are you trying to populate m_list, C++ side or inside some QML file?

    Br,
    Villep

  5. #5
    Registered User
    Join Date
    Jun 2012
    Posts
    105

    Re: QT QDeclarativeImageProvider child class single instance?

    Quote Originally Posted by tkastlunger View Post
    From inside ::componentComplete of the plugin.
    How would I be able to populate the plugin from QML with C++? Would be intresting to know .

  6. #6
    Nokia Developer Expert
    Join Date
    Jun 2012
    Posts
    55

    Re: QT QDeclarativeImageProvider child class single instance?

    How are you calling ::componentComplete? You can also try adding some variable in your that you increment each time requestImage is called to make sure it gets incremented with a single instance.
    Something like
    Code:
    #include <QDebug>
    
    class QMyImgProvClass : public QDeclarativeImageProvider {
    public:
        QMyImgProvClass() : mNumberOfCalls(0)
        {   
        }    
        ...
        virtual QImage requestImage(const QString &id, QSize *size, const QSize& requestedSize){
            ...
            ++mNumberOfCalls;
            
            qDebug() << "Calls:" << mNumberOfCalls; 
        }
    
    public:
        QList<int> m_list;
    
    private:
        int mNumberOfCalls;
    };
    Br,
    Villep

  7. #7
    Registered User
    Join Date
    Jun 2012
    Posts
    105

    Re: QT QDeclarativeImageProvider child class single instance?

    ::componentComplete is called by the QML backend, I personally do not call it directly.
    The strange thing is that the list _is_ populated, if I access it through the singleton. If I access it from within the requestImage, as in:

    virtual QImage requestImage(const QString &id, QSize *size, const QSize& requestedSize){
    ...
    if (m_list.size() > 0)
    // this is never reached because m_list is empty

    }

    whilst this in turn:

    virtual QImage requestImage(const QString &id, QSize *size, const QSize& requestedSize){
    ...
    if (QMyImgProvClass::Instance().m_list.size() > 0)
    // this is reached just fine.

    }

Similar Threads

  1. Single instance (Meego harmattan)
    By kompotFX in forum Nokia N9
    Replies: 2
    Last Post: 2011-08-11, 08:44
  2. Single instance of process...
    By pornima in forum Symbian C++
    Replies: 6
    Last Post: 2009-08-26, 14:47
  3. Replies: 4
    Last Post: 2009-02-17, 05:47
  4. Replies: 6
    Last Post: 2007-03-14, 12:56

Posting Permissions

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