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. Do QGrahpicsItems need to be dynamicall allocated?
Qt 6.11 is out! See what's new in the release blog

Do QGrahpicsItems need to be dynamicall allocated?

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 1.4k 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.
  • C Offline
    C Offline
    cuddlykittens11
    wrote on last edited by
    #1

    I'm working on porting my PyQt app to C++, I've always run into a few bumps here and there, but for the most part it's been pretty smooth. The app makes heavy use of the QGraphicsView Framework.

    So let's say I had an object "A," that is a sublcass of "QGraphicsObject," A has a method ".size()," which will return a QSize. It also has some calls to qDebug() in its constructor.

    When I made a static instance of A (identified by "b,"), I didn't see any output on the terminal and I got an error like this:

    @main.cpp:22:4: error: request for member ‘info’ in ‘b’, which is of non-class type ‘A()’
    b.size();
    @

    When I did a dynamically allocated instance, it worked fine and I saw a message on the terminal.

    Can someone explain what's up with this here?

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

      Hi,

      Do you mean something like:

      @b = A@

      vs

      @b = A()@

      ?

      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
      • C Offline
        C Offline
        cuddlykittens11
        wrote on last edited by
        #3

        The second one.

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

          My question was not clear enough.

          Can you post the code that is failing and then one that is successful ?

          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
          • C Offline
            C Offline
            cuddlykittens11
            wrote on last edited by
            #5

            When I do:
            @A b(/parameters/)@
            The complilation fails.

            If I do:
            @A b;@
            (Using either default or no parameters), it works out fine.

            And if I do:
            @A *b = new A(/parameters/);@
            It works fine.

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

              Ok, it's clearer now, I've misread your initial post…

              What parameters are you giving that makes it fail ?

              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
              • C Offline
                C Offline
                cuddlykittens11
                wrote on last edited by
                #7

                It might be because I forogt to add the "explicit," keyword to my constrcutors. My Bad....

                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