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. Mach to Qt standard
Forum Updated to NodeBB v4.3 + New Features

Mach to Qt standard

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 3 Posters 654 Views
  • 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.
  • D Offline
    D Offline
    Damian7546
    wrote on last edited by Damian7546
    #1

    Hi,

    How change my error list creted in standard C++ to Qt posibility:

    class MyError
    {
        int ErrorCode;
    public:
        std::map<int, std::string> ErrorList;
        MyError(int ErrCode)
        {
            ErrorCode = ErrCode;
            ErrorList[0x00] = "Unknown error.";
        }
        std::string getMessage() {
            return this->ErrorList[this->ErrorCode];
        }
    };
    

    ?

    Regards

    jsulmJ 1 Reply Last reply
    0
    • D Damian7546

      Hi,

      How change my error list creted in standard C++ to Qt posibility:

      class MyError
      {
          int ErrorCode;
      public:
          std::map<int, std::string> ErrorList;
          MyError(int ErrCode)
          {
              ErrorCode = ErrCode;
              ErrorList[0x00] = "Unknown error.";
          }
          std::string getMessage() {
              return this->ErrorList[this->ErrorCode];
          }
      };
      

      ?

      Regards

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Damian7546 said in Mach to Qt standard:

      How change my error list creted in standard C++ to Qt posibility:

      What does this mean and why do you need to change it?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      D 1 Reply Last reply
      0
      • jsulmJ jsulm

        @Damian7546 said in Mach to Qt standard:

        How change my error list creted in standard C++ to Qt posibility:

        What does this mean and why do you need to change it?

        D Offline
        D Offline
        Damian7546
        wrote on last edited by
        #3

        @jsulm Hmm,
        I am thinking change currently used:

        #include <map>
        #include <string>
        

        to:

        #include <QMap>
        #include <QString>
        

        What do you think ?

        jsulmJ 1 Reply Last reply
        0
        • D Damian7546

          @jsulm Hmm,
          I am thinking change currently used:

          #include <map>
          #include <string>
          

          to:

          #include <QMap>
          #include <QString>
          

          What do you think ?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Damian7546 You can do that (but you can also use std container in Qt applications). What is the problem?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          D 1 Reply Last reply
          3
          • jsulmJ jsulm

            @Damian7546 You can do that (but you can also use std container in Qt applications). What is the problem?

            D Offline
            D Offline
            Damian7546
            wrote on last edited by
            #5

            @jsulm Ok,
            So if I stay in oryginal library, please tell me how can I normalize :
            typedef std::vector<unsigned char> vec_bytes; to using QByteArray ?

            Examle:

            void MyFunction::showresponse(const QByteArray &result)
            {
                if(this->CheckErrors(result__)) {
                    //do something
                }
            }
            

            How convert QByteArray resutl; to vec_bytes result__; ?

            jsulmJ 1 Reply Last reply
            0
            • D Damian7546

              @jsulm Ok,
              So if I stay in oryginal library, please tell me how can I normalize :
              typedef std::vector<unsigned char> vec_bytes; to using QByteArray ?

              Examle:

              void MyFunction::showresponse(const QByteArray &result)
              {
                  if(this->CheckErrors(result__)) {
                      //do something
                  }
              }
              

              How convert QByteArray resutl; to vec_bytes result__; ?

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Damian7546 In you case it seems to be way easier to use QByteArrray instead of std::vector<unsigned char> (change vec_bytes result__ to QByteArray).
              If you want to have such a mix then you will need to iterate over the QByteArray elements and add them to std::vector<unsigned char>.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              D 1 Reply Last reply
              1
              • jsulmJ jsulm

                @Damian7546 In you case it seems to be way easier to use QByteArrray instead of std::vector<unsigned char> (change vec_bytes result__ to QByteArray).
                If you want to have such a mix then you will need to iterate over the QByteArray elements and add them to std::vector<unsigned char>.

                D Offline
                D Offline
                Damian7546
                wrote on last edited by
                #7

                @jsulm I decided to change all to Qt standard.

                Actually I do not know how change insert function in below line:

                buffer.insert(std::end(buffer), std::begin(CRC), std::end(CRC));

                where buffer is as ``QByteArray.

                JonBJ 1 Reply Last reply
                0
                • D Damian7546

                  @jsulm I decided to change all to Qt standard.

                  Actually I do not know how change insert function in below line:

                  buffer.insert(std::end(buffer), std::begin(CRC), std::end(CRC));

                  where buffer is as ``QByteArray.

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #8

                  @Damian7546
                  Why mix Qt and std:: stuff? You want to append to buffer, so why not search QByteArray doc page for append (or insert), e.g. QByteArray &QByteArray::append(const QByteArray &ba) ?

                  D 1 Reply Last reply
                  1
                  • JonBJ JonB

                    @Damian7546
                    Why mix Qt and std:: stuff? You want to append to buffer, so why not search QByteArray doc page for append (or insert), e.g. QByteArray &QByteArray::append(const QByteArray &ba) ?

                    D Offline
                    D Offline
                    Damian7546
                    wrote on last edited by
                    #9

                    @JonB

                     QByteArray CRC = this->GetCRC16(buffer, buffer.size());  
                     buffer.append(CRC);
                    

                    it will be correct ?

                    JonBJ 1 Reply Last reply
                    0
                    • D Damian7546

                      @JonB

                       QByteArray CRC = this->GetCRC16(buffer, buffer.size());  
                       buffer.append(CRC);
                      

                      it will be correct ?

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by JonB
                      #10

                      @Damian7546

                      • We don't know since we don't know what this->GetCRC16(buffer, buffer.size()) does or returns.

                      • If I had to guess, I would say this is not right. If you are passing buffer, buffer.size() to GetCRC16() what does that do in buffer and why would you want to append the result to CRC if you have already called something which perhaps/at a guess already appends there? [Actually, it may be correct, provided GetCRC16() reads buffer.size() bytes from buffer and returns a new QByteArray, does not write into buffer.]

                      1 Reply Last reply
                      1

                      • Login

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