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. [solved] variable needs curly braces ... any idea?

[solved] variable needs curly braces ... any idea?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 1.4k 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.
  • S Offline
    S Offline
    SherifOmran
    wrote on 2 Nov 2013, 12:55 last edited by
    #1

    @
    QPointer <QGraphicsScene> viewScene[2] = new QGraphicsScene();
    @
    When i compile it into windows i get, viewscene array needs curly braces. However, it works fine in MAC ..

    the same also in this line
    @
    QPointer <QGraphicsTextItem> io[8] = new QGraphicsTextItem;
    @

    Any ideas?

    thanks

    1 Reply Last reply
    0
    • J Offline
      J Offline
      JKSH
      Moderators
      wrote on 2 Nov 2013, 15:19 last edited by
      #2

      Hi,

      This is an array of 2 pointers:
      @
      QPointer <QGraphicsScene> viewScene[2]
      @

      This returns one pointer:
      @
      new QGraphicsScene();
      @

      This is an array of 8 pointers:
      @
      QPointer <QGraphicsTextItem> io[8]
      @

      This returns one pointer:
      @
      new QGraphicsTextItem;
      @

      It doesn't work fine on the Mac -- your Mac compiler just didn't notice the mistake. You can't assign one pointer to an array of pointers.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SherifOmran
        wrote on 2 Nov 2013, 15:57 last edited by
        #3

        thank you for your reply

        this means, i should correct it this way, please correct me if i mistake
        @
        QPointer <QGraphicsScene> viewScene[2] = new QGraphicsScene2;
        @

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SherifOmran
          wrote on 2 Nov 2013, 17:36 last edited by
          #4

          solved

          @
          QPointer <QGraphicsScene> viewScene[2] = {new QGraphicsScene()};
          @

          @
          QPointer <QGraphicsTextItem> io[8] = { new QGraphicsTextItem };
          @

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mmoll
            wrote on 4 Nov 2013, 08:52 last edited by
            #5

            This is most likely not what you want. It creates an array of 2 (8) QPointers, of which only the first is initialized to point to a new object. The others are zero-initialized.

            As these are rather elementary C++ syntax questions, I think you should try to find a good book on C++ first.

            1 Reply Last reply
            0

            3/5

            2 Nov 2013, 15:57

            • Login

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