Declare const array of struct

  • Hello,

    I have the following code in cpp file:

    #include "xxx.h"
    typedef struct {
     int icon;
     QRect geometry;
     int layer;
     QString iconName;
    } icon_s;
    const icon_s icon[] = 
     { 1, QRect(0,0,10,10), 1, "iconName1.png" },
     { 2, QRect(10,10,10,10), 1, "iconName2.png"}
    //Here begins the constructor of the class
    MyWidget::MyWidget(QWidget *parent) :
     ui(new Ui::MyWidget)
    void MyWidget::placeIcon()
     int iconNumber = icon[0].icon;
     QString file = icon[0].iconName;

    What I would like to know if this is the correct way in QT to define this kind of const ?

    Thanks in advance..


  • Lifetime Qt Champion

    @ploef said:

    Except that typedef struct is a bit c-ish ,
    then its a fine method. :)

Log in to reply

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