Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] use the struct (inside a class)
Forum Updated to NodeBB v4.3 + New Features

[Solved] use the struct (inside a class)

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 10.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MohammadReza
    wrote on 1 Jul 2014, 07:48 last edited by
    #1

    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.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 1 Jul 2014, 08:08 last edited by
      #2

      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;
      @

      (Z(:^

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MohammadReza
        wrote on 1 Jul 2014, 08:26 last edited by
        #3

        Here is an another example:

        mmm.h
        @
        #ifndef MMM_H
        #define MMM_H

        #include <QObject>

        class mmm : public QObject
        {
        Q_OBJECT

        public:
        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;  ----------&gt; does not work!
        
        return a.exec&#40;&#41;;
        

        }
        @

        I want to define a variable of MyStruct in main.cpp

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sierdzio
          Moderators
          wrote on 1 Jul 2014, 08:29 last edited by
          #4

          Remove that "typedef", it is not needed.

          And define the variable using mmm::MyStruct syntax.

          (Z(:^

          1 Reply Last reply
          0
          • I Offline
            I Offline
            IamSumit
            wrote on 1 Jul 2014, 09:12 last edited by
            #5

            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!

            Be Cute

            1 Reply Last reply
            0
            • M Offline
              M Offline
              MohammadReza
              wrote on 1 Jul 2014, 09:15 last edited by
              #6

              Thank you very very much dear sierdzio.
              Worked!

              1 Reply Last reply
              0
              • S Offline
                S Offline
                sierdzio
                Moderators
                wrote on 1 Jul 2014, 09:44 last edited by
                #7

                You are welcome, have fun :-)

                (Z(:^

                1 Reply Last reply
                0

                1/7

                1 Jul 2014, 07:48

                • Login

                • Login or register to search.
                1 out of 7
                • First post
                  1/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved