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. Declare const array of struct
Forum Updated to NodeBB v4.3 + New Features

Declare const array of struct

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 1.5k 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.
  • P Offline
    P Offline
    ploef
    wrote on 2 Jun 2016, 11:29 last edited by
    #1

    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

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 2 Jun 2016, 11:44 last edited by
      #2

      @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

      1 Reply Last reply
      1

      1/2

      2 Jun 2016, 11:29

      • Login

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