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) :
     QDialog(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..

    Regards


  • Qt Champions 2017

    @ploef said:

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

    http://stackoverflow.com/questions/612328/difference-between-struct-and-typedef-struct-in-c


Log in to reply
 

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