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. Dynamic structure error
Forum Updated to NodeBB v4.3 + New Features

Dynamic structure error

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 486 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.
  • AlvaroSA Offline
    AlvaroSA Offline
    AlvaroS
    wrote on last edited by
    #1

    Hi to all.
    First of all thank for helping me and reading this post.

    I am trying to create a dynamic structure.
    My code is:

    Header:

    typedef struct { //We define the line structure
        std::double_t x_start;
        std::double_t x_end;
        }struc_lines;
    
    private
        std::vector<struc_lines> lines_struct;
    

    Now I would like to add x_start and x_end to the structure which we do not know the size (so because of that it is a dynamic structure).

    I have tried with

     lines_struct[i].y_start=(1.25); //For example
    

    It compiles fine but it does not work.
    How can I use .push_back for example in lines_struct.x_start???

    Thanks a lot.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      You mean

      struc_lines Line;
      Line.x_start=100;
      lines_struct.push_back(Line);

      Now it has 1 entry so
      QDebug() << lines_struct[0].x_start;
      should give 100.

      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