[Solved] use the struct (inside a class)
-
wrote on 1 Jul 2014, 07:48 last edited by
Hi friends.
I want to have a class & some structs inside it.
In my main class, I want to define a varible of struct.For example
@
MyClass
typedef struct MyStruct
{
int a;
int b;
int c;
int d;
}MyStruct;
Q_DECLARE_METATYPE(MyStruct)
@@
MainClass
struct MyStruct xyz;
@Thanks a lot.
Ya Ali. -
And do you have any question or problem?
Just guessing, that something does not work, I'll post a code that should be OK:
@
MyClass
struct MyStruct
{
int a;
int b;
int c;
int d;
};MainClass
MyStruct xyz;
@ -
wrote on 1 Jul 2014, 08:26 last edited by
Here is an another example:
mmm.h
@
#ifndef MMM_H
#define MMM_H#include <QObject>
class mmm : public QObject
{
Q_OBJECTpublic:
explicit mmm(QObject *parent = 0);
typedef struct MyStruct
{
int a;
int b;
int c;
int d;
};signals:
public slots:
};
#endif // MMM_H
@mmm.cpp
@
#include "mmm.h"mmm::mmm(QObject *parent) :
QObject(parent)
{}
@main.cpp
@
#include <QCoreApplication>
#include "mmm.h"int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);mmm instance; instance.MyStruct xyz; ----------> does not work! return a.exec();
}
@I want to define a variable of MyStruct in main.cpp
-
Remove that "typedef", it is not needed.
And define the variable using mmm::MyStruct syntax.
-
wrote on 1 Jul 2014, 09:12 last edited by
Hii,
you can do as well.
@
class ABC
struct EventInfo
{
QString mcstrCMD_ID;
QString mcstrTYPE;
QString mcsKEYBOARDEVENT;
QString mcstrX;
QString mcstrY;
}eventInfo;@
@
ABC hh;
QString strID=hh.eventInfo.mcstrCMD_ID;
@
hope it helps! -
wrote on 1 Jul 2014, 09:15 last edited by
Thank you very very much dear sierdzio.
Worked! -
You are welcome, have fun :-)
1/7