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. Hot to convert (cast) QHash<int, StructOfQByteArray1AndQbyteArray2> to QHash<int, QByteArray1> with minimum resource cost?
Forum Updated to NodeBB v4.3 + New Features

Hot to convert (cast) QHash<int, StructOfQByteArray1AndQbyteArray2> to QHash<int, QByteArray1> with minimum resource cost?

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 2.1k Views 2 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.
  • K Offline
    K Offline
    Kofr
    wrote on last edited by
    #1

    ok. let's find out how well do you know C++.
    ok we have

    struct StructOfQByteArray1AndQbyteArray2 {
        QByteArray array1;
        QByteArray array2;
    }
    

    Hot to convert (cast) QHash<int, StructOfQByteArray1AndQbyteArray2> to QHash<int, QByteArray1> with minimum resource cost?

    where I want to use this?
    when working with QAbstractItemModel I implement method QHash<int, QByteArray> QAbstractItemModel::roleNames() const but in app I have more complex QHash<int, StructOfQByteArray1AndQbyteArray2> with some extra data.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      well if u want to avoid copy bytearray
      maybe use something like
      QHash<int, QByteArray1 *>
      and set to point to the real QByteArray1; ?

      K 1 Reply Last reply
      0
      • mrjjM mrjj

        well if u want to avoid copy bytearray
        maybe use something like
        QHash<int, QByteArray1 *>
        and set to point to the real QByteArray1; ?

        K Offline
        K Offline
        Kofr
        wrote on last edited by
        #3

        @mrjj but I have to return exactly data, not pointer QHash<int, QByteArray> QAbstractItemModel::roleNames() const

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Kofr said:

          ahh its something you must return.

          Well i think u need copy then since i doubt there is way to cast the original
          StructOfQByteArray1AndQbyteArray2

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

            From a C++ POV: you can't do such a cast.

            What resources do you want to optimize ? Speed ? Memory use ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            K 1 Reply Last reply
            1
            • SGaistS SGaist

              Hi,

              From a C++ POV: you can't do such a cast.

              What resources do you want to optimize ? Speed ? Memory use ?

              K Offline
              K Offline
              Kofr
              wrote on last edited by
              #6

              @SGaist Speed. So you want to say that it is ok to manually fill in QHash<int, QByteArray> before returning and just allow data to be copied as rvalue?

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                I'm just saying that you can't cast (as in static_cast, dynamic_cast etc.) such a hash of int and struct to a hash of int and QByteArray.

                Are your role names going to be dynamically created ? Changed ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                K 1 Reply Last reply
                0
                • SGaistS SGaist

                  I'm just saying that you can't cast (as in static_cast, dynamic_cast etc.) such a hash of int and struct to a hash of int and QByteArray.

                  Are your role names going to be dynamically created ? Changed ?

                  K Offline
                  K Offline
                  Kofr
                  wrote on last edited by
                  #8

                  @SGaist yes, I will have custom roles for some delegates.

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Ok but these roles are already known, no ?

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0

                    • Login

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