0

I am using Qt 5.4 for my android and iOS.

I have a C# code,but I don't know how to convet it to Qt(C++).

In C#
A.cs

namespace WS
{
        public enum myTypes
        {
            T1,
            T2,
            T3,
        };

         public abstract class GS
        {
           protected Color _penColor = Color.White;
           protected bool ReadBaseProperty(BinaryReader reader, string readFileVersion)
            {...
            }
        }...
}

B.cs

namespace WS
{
    public class sL : GS
    {
        public virtual int PC
        {
            get { return PointList.Count; }
        }...
     }
}

In Qt, I try

A.h

namespace WS{
   class GS
   {
    public:
    GS();
   }
}

the another file:

A.cpp

#include "GS.h"
WS::GS::GS(){}

the another file:
B.h

namespace WS{
   class sL:public GS
   {
    public:
    sL();
   }
}

the another file:
B.cpp

#include "B.h"
WS::sL::sL(){}

Is it a correct format for Qt?

weilun
  • 53
  • 1
  • 13

1 Answers1

0

Not exactly sure what you are trying to do, but I'll give it a go.

There's no 1-to-1 conversion from C# to C++ However here are the parts that you can convert:

A.cs

namespace WorkSystem
{
    enum myTypes
    {
        T1,
        T2,
        T3
    };

    class GS
    {
        protected:
            GS() { }
    };
}

GS has a protected constructor to prevent initialization, there's no such thing as abstract in C++

B.cs

namespace WorkSystem
{
    class sL : public GS
    {
        public:
            virtual ~sL() { }

            virtual int getPC()
            {
                return 0;
            }
    };
}

sL has a so-called virtual destructor

Now for the other parts:

  • Color: This is a System.Drawing structure, which is NOT C++, but C++/CLI.

  • BinaryReader: This is a class only available in C#. To read from files you have to use stdio or a third party library.

  • PC: Properties are not available in C++, instead you use functions as getters and setters.

  • PointList.Count: I'm assuming this is a C# list class. Again these do not exist in C++, but can be replaced by a std::list

Community
  • 1
  • 1
Neijwiert
  • 985
  • 6
  • 19
  • You write A.cs and B.cs? Do you mean A.cpp and B.cpp? If so,what about A.h and B.h? By the way, I thought the namespace should be in .h file...>/// – weilun Oct 05 '15 at 04:53