Q_PROPERTY not shown

I am using Q_PROPERTY with QML. My code is:

using namespace std; typedef QString lyricsDownloaderString; // this may be either std::string or QString class lyricsDownloader : public QObject { Q_OBJECT public: Q_PROPERTY(QString lyrics READ lyrics NOTIFY lyricsChanged) Q_INVOKABLE virtual short perform() = 0; inline void setData(const string & a, const string & t); // set artist and track Q_INVOKABLE inline void setData(const QString & a, const QString & t); // for QStrings Q_INVOKABLE inline bool anyFieldEmpty(); // check whether everything is filled inline QString lyrics() { return lyrics_qstr; } /*some more data*/ signals: void lyricsChanged(QString); }; class AZLyricsDownloader : public lyricsDownloader { Q_OBJECT public: AZLyricsDownloader() : lyricsDownloader("", "") {} AZLyricsDownloader(const string & a, const string & t) : lyricsDownloader(a, t) {} Q_INVOKABLE short perform(); //Q_INVOKABLE inline void setData(const string & a, const string & t);// set artist and track protected: /*some more data*/ }; 

and one of the pages in QML is

 import QtQuick 1.1 import com.nokia.meego 1.0 import com.nokia.extras 1.0 Page { id: showLyricsPage tools: showLyricsToolbar Column { TextEdit { id: lyricsview anchors.margins: 10 readOnly: true text: azdownloader.lyrics } } Component.onCompleted: { azdownloader.perform() busyind.visible = false } BusyIndicator {id: busyind /**/ } ToolBarLayout {id: showLyricsToolbar/**/} // Info about disabling/enabling edit mode InfoBanner {id: editModeChangedBanner /**/} } 

azdownloader is an AZLyricsDownloader object

Codes are correctly executed in C ++, the function returns the text that should be in TextEdit.

But unfortunately, TextEdit is empty. There is no text. there is no body for the signal, but it does not need the AFAIK signal.

If i use

 Q_PROPERTY(QString lyrics READ lyrics CONSTANT) 

The result is the same.

What am I doing wrong?

+4
source share
1 answer

When you change the value of the lyrics property in C ++ code, you should send a signal to the NOTIFY properties (here void lyricsChanged(); ):

 this->setProperty("lyrics", myNewValue); emit lyricsChanged(); 

In this case, QML should update the property value.

+8
source

All Articles