PDA

View Full Version : Crash during use of Active QT + QVariantList in C# application



Vagesh
26th December 2014, 11:08
Hi All,

I have written following class in QT and I would like to access the array of following class object in C# application. But when I try to access it then it is causing the crash.

Like

MyClassAx a;

a.Devices.Length; ///////Crash here;


class Q_DECL_EXPORT DeviceInfo : public QObject
{
Q_OBJECT


Q_CLASSINFO("ClassID", "{B4A5BD09-67FF-4869-B777-E91A59E08FF3}")
Q_CLASSINFO("InterfaceID", "{A5F87FDA-F796-41C8-9C03-86A50AA7F963}")
QString m_sDeviceName;
bool m_bState;
bool m_bPreferred;


public:
DeviceInfo() {}
DeviceInfo(const DeviceInfo& src);
DeviceInfo(QString sDeviceName,QObject *parent = 0);
void SetIsPreferred(bool bPreferred);

void SetState(bool bState);
~DeviceInfo();
signals:

public slots:
bool GetState() const;
bool IsPreferred() const;

QString GetName() const;
};
Q_DECLARE_METATYPE(DeviceInfo)



Following is the class which is exported as activex class

class Q_DECL_EXPORT MyClassAx : public QWidget
{

Q_OBJECT

Q_CLASSINFO("ClassID", "{75C97E48-AEBC-48C6-A4F5-80B462FD4E18}")
Q_CLASSINFO("InterfaceID", "{C5845DAD-4E7D-481A-8ECE-FC1FF81E5FE7}")
Q_CLASSINFO("EventsID", "{74C81852-2012-4333-A5A7-BD7D43B487D1}")
// Q_CLASSINFO("Version", "1.0")
Q_CLASSINFO("Description", "My class activex description")
Q_CLASSINFO("StockEvents","yes")
Q_CLASSINFO("ToSuperClass","MyClassAx")
QVariantList variantList;

Q_PROPERTY(QList<QVariant> Devices READ GetDevicesList)
public:
QList<QVariant> GetDevicesList()
{
QList<DeviceInfo> dev;
////Code to retrive the dev list
for(int i=0;i<dev.size();i++)
{

variantList.append(QVariant::fromValue(dev[i]));
}
return variantList;
}
}



Please let me know what i am missing

Vagesh
26th December 2014, 14:05
My issue is get resolved by following this example.
http://doc.qt.io/qt-5/activeqt-activeqt-comapp-example.html