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
Qt 6.11 is out! See what's new in the release blog

Declare const array of struct

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 1.9k 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 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
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on 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

      • Login

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