I'm starting to want to use the Q_PROPERTY system for a specific case. I have a class with a member which contains the information used in various modeless dialogs. However, since these dialogs are modeless, the information might be altered while they are running. So I thought of transforming this member into a Q_PROPERTY with a NOTIFY signal that I could then connect to the dialogs so they'd refresh themselves should this data be altered. However, the member is now no longer detected as a class data member and thus the class fails to compile (giving hundreds of "undeclared identifier" errors).
The class declaration is the following:
class Canvas : public QSFMLCanvas
{
Q_OBJECT
Q_PROPERTY(std::vector<Fault> faults READ GetFaults WRITE SetFaults NOTIFY FaultsEdited)
Q_PROPERTY(std::vector<Horizon> horizons READ GetHorizons NOTIFY HorizonsEdited)
/*...*/
//std::vector<Fault> faults;
//std::vector<Horizon> horizons;
/*...*/
public:
std::vector<Fault> GetFaults() const;
void SetFaults(std::vector<Fault> v);
std::vector<Horizon> GetHorizons() const;
/*...*/
signals:
void FaultsEdited();
void HorizonsEdited();
};
class Canvas : public QSFMLCanvas
{
Q_OBJECT
Q_PROPERTY(std::vector<Fault> faults READ GetFaults WRITE SetFaults NOTIFY FaultsEdited)
Q_PROPERTY(std::vector<Horizon> horizons READ GetHorizons NOTIFY HorizonsEdited)
/*...*/
//std::vector<Fault> faults;
//std::vector<Horizon> horizons;
/*...*/
public:
std::vector<Fault> GetFaults() const;
void SetFaults(std::vector<Fault> v);
std::vector<Horizon> GetHorizons() const;
/*...*/
signals:
void FaultsEdited();
void HorizonsEdited();
};
To copy to clipboard, switch view to plain text mode
As well, should I uncomment the original data members, it compiles just fine, but the NOTIFY signal is not emitted.
Bookmarks