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. How to create a QList<QGraphicsItem>

How to create a QList<QGraphicsItem>

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 342 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.
  • F Offline
    F Offline
    frnklu20
    wrote on last edited by
    #1

    It would help me a lot if i could do tis, but it gives me an error if i try to

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

      Hi,

      What are you doing ?
      What errors do you get ?

      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
      1
      • F Offline
        F Offline
        frnklu20
        wrote on last edited by
        #3

        hi,

        QList<QGraphicsItem> list;
        

        in the code it doesn't show any error, but in the compiler it says
        "ivalid abstract return type 'QGraphicsItem'"

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

          Hi
          Should that not be
          QList<QGraphicsItem *>
          so its a list of pointers to QGraphicsItem's
          also the scene has such list already. (just in case)
          https://doc.qt.io/qt-5/qgraphicsscene.html#items

          1 Reply Last reply
          6
          • S Offline
            S Offline
            spobit
            wrote on last edited by spobit
            #5

            QList will call follow code to create object:

            template <typename T>
            Q_INLINE_TEMPLATE void QList<T>::node_construct(Node *n, const T &t)
            {
                if (QTypeInfo<T>::isLarge || QTypeInfo<T>::isStatic) n->v = new T(t);
                else if (QTypeInfo<T>::isComplex) new (n) T(t);
            #if (defined(__GNUC__) || defined(__INTEL_COMPILER) || defined(__IBMCPP__)) && !defined(__OPTIMIZE__)
                // This violates pointer aliasing rules, but it is known to be safe (and silent)
                // in unoptimized GCC builds (-fno-strict-aliasing). The other compilers which
                // set the same define are assumed to be safe.
                else *reinterpret_cast<T*>(n) = t;
            #else
                // This is always safe, but penaltizes unoptimized builds a lot.
                else ::memcpy(n, static_cast<const void *>(&t), sizeof(T));
            #endif
            }
            

            But QGraphicsItem is a abstract class, See, boundingRect(), paint(), that causes compilation to failed.

            1 Reply Last reply
            2

            • Login

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