0

I have a GUI displaying a tree architecture as shown here.

enter image description here

Each of those nodes are separate classes that are derived from the node above them. All of them inherit QObject for their implementation. Now I need to add a few properties to be displayed when the user selects Properties under the Right-Click menu of Implicit. Selecting this opens a window with the properties. I added these properties in the header file of Implicit like so :

#ifndef FCIMPLICIT_H
#define FCIMPLICIT_H
#include <QObject>
#include "Interface.h"
#include "ResourceItem.h"
#include "MonWindow.h"
#include "FCTab.h"
#include "ResourceItem.h"
#include "FCAbstract.h"
#include "FCInterface.h"
#include "FCConnections.h"
class CFCImplicit: public CResourceItem
{

    Q_OBJECT
    Q_PROPERTY(int FCPortID READ getPortID )
    Q_PROPERTY(QString Type READ getType )
    Q_PROPERTY(QString Status READ getStat )    
    Q_PROPERTY(int WWNodeNumber READ getNodeNo )
    Q_PROPERTY(int WWPortNumber READ getPortNo )
    Q_PROPERTY(bool AutoActive READ getAuto )
public:
    CFCImplicit(QObject*);
    ~CFCImplicit();

    QString                 getType();
    QString                 getStat();
    int                     getPortID();
    int                     getPortNo();
    int                     getNodeNo();
    bool                    getAuto();


};

FCinterface.h is the header of the FCASM node.

The issue is that only the first property is displayed, as seen in the second picture. Is there a reason why this is happening? Am I supposed to add something to the constructor or a new function?

The constructor for the Implicit class is

CFCImplicit::CFCImplicit(QObject* parent) : CResourceItem(parent)
{

    fnSetProperty("objectName", QString("Implicit"));   
    ((CResourceItem*)parent)->fnAddResources(this);

}

EDIT:

This is the code for all the READ functions

QString CFCImplicit::getType()
{
QString a;
a="Implicit";
return a;
}

QString CFCImplicit::getStat()
{QString a;
a="Idle";
return a;}

int CFCImplicit::getPortID()
{int a;
a=1;
return a;}

int CFCImplicit::getPortNo()
{int a;
a=2;
return a;}

int CFCImplicit::getNodeNo()
{int a;
a=2;
return a;}

bool CFCImplicit::getAuto()
{bool a;
a=true;
return a;}
Michael Thomas
  • 443
  • 1
  • 4
  • 8
  • Can you show us the code where you extract the properties of the selected object to add them in the property table? – Benjamin T May 18 '17 at 07:32
  • @BenjaminT I have added the code but they don't do anything. I defined them just so that I could demonstrate the addition of properties. The functions just return predefined values. – Michael Thomas May 18 '17 at 07:36
  • I did not mean the code of the getters. I meant the code where you retrieve the list of properties of the object. It should contains calls to `QMetaObject::propertyCount()` annd `QMetaObject::property(int)`. – Benjamin T May 18 '17 at 07:57
  • I haven't added any code for that. What purpose do those lines serve? I am going to (wrongly, perhaps) assume that they only return an `int` with the number of properties, if so how do they affect the properties being displayed? – Michael Thomas May 18 '17 at 08:18
  • 1
    Yes you did add code for that. Either by writing it directly or by using a library. To understand why the properties are not displayed in the property table, you need to find how the property table works. Si if you do not give any detail about the property table, no one will be able to help you. (on a side note, do not assume what a function does, but read the doc!) – Benjamin T May 18 '17 at 08:40
  • Could you explain what you meant by details about the property table? I am building these additional features on top on a lot of existing code. I thought that the property window was an object that belonged to `QObject`. Should I be looking for a custom class that describes this property table? (And I am going through the `QMetObject` doc as we speak! ) – Michael Thomas May 18 '17 at 08:48

2 Answers2

0

I found out what I was doing wrong. I assumed that since the properties were read only, I only needed a READ accessor function. By adding the WRITE accessor and adding the required WRITE functions, the properties were displayed. I don't exactly understand why this condition is required (maybe having just READ just makes the properties available for introspection), but it worked! So there you go.

Happy coding everyone!

Michael Thomas
  • 443
  • 1
  • 4
  • 8
0

No need to add the READ and the function, you can use the MEMBER to have direct access to the variable.

Tomaz Canabrava
  • 2,320
  • 15
  • 20
  • I'm using [Qt 4.7.0](https://doc.qt.io/archives/qt-4.7/properties.html) , MEMBER wasn't added until later versions. I'm terribly sorry, I should have mentioned that. – Michael Thomas May 18 '17 at 09:41
  • can't you update Qt? I mean, 4.7 is unmaintained for a *long* time. – Tomaz Canabrava May 18 '17 at 12:29
  • I realised that when I had to look for documentation in the Qt archives! But it is a company project, and they developed it in 4.7. Will it work just the same in later versions of Qt? Are later versions just additions to the older versions or have they changed how different things work? – Michael Thomas May 19 '17 at 04:34
  • A few things should change but if you are using Qt Widgets there are not many changes - A lot of projects still compiles with Qt4 *and* Qt5 together, same codebase. – Tomaz Canabrava May 19 '17 at 07:47