@d_stranz
Thank you so very much!! As you can see, my knowledge in Qt is fairly limited. But with the help of supportive experts like you, people like me will surely learn!
@d_stranz
Thank you so very much!! As you can see, my knowledge in Qt is fairly limited. But with the help of supportive experts like you, people like me will surely learn!
@d_stranz
I tried implementing the code, but there was no change in the GUI. By using breakpoints I found that the qobjectcast was returning a null pointer (pConn ==nullptr). Could you take a stab at why this could possibly be happening?
Is the CFCConnection class derived from QObject somewhere in its inheritance hierarchy? Is the Q_OBJECT macro present in the class definition in the header file? Is MOC being run on the header file?
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
Yes, yes and yes.
The code to demonstrate the first two points:
Qt Code:
#include <QObject> //Included QObject #include "ResourceItem.h" #include "MonWindow.h" #include "FCTab.h" #include "ResourceItem.h" #include "FCAbstract.h" #include "FCInterface.h" class CFCConnections: public CResourceItem { Q_OBJECT //QObject MACRO public: ~CFCConnections(); private: CFCInterface* pParent; }; #endifTo copy to clipboard, switch view to plain text mode
That was the FCConnections.h code. And I know that MOC has run on the header file because I had to manually change its build step to include MOC. This image below shows the inheritance hierarchy. CFCConnections is derived from CResourceItem which has QObject as its base class.
1.jpg
POSSIBLE SOLUTION
I just had to change the line
Qt Code:
CFCConnections* f_pConn=0;To copy to clipboard, switch view to plain text mode
to
Qt Code:
CFCConnections* f_pConn; f_pConn = new CFCConnections(this);To copy to clipboard, switch view to plain text mode
Last edited by cryomicl; 16th May 2017 at 09:17.
So you mean to say you were trying to add a NULL pointer to an instance of CFCConnection to your hierarchy? Of course that won't work. qobject_cast<> won't magically turn a NULL or uninitialized pointer into a real one, it turns a real pointer to some QObject-based class into a pointer to another QObject-based class if the conversion is valid (that is, the type you are trying to cast to inherits from the type that is passed in).I just had to change the line
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
Bookmarks