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



  • @
    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


  • Moderators

    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.



  • 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;
    @



  • solved

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

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



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.