title: How to initialize Objects in a QList in a loop
body: <p>In My class I have a member variable;</p>
  
  <pre><code>QProcess* p1;
  </code></pre>
  
  <p>Inside some function, i initialize and use it as:</p>
  
  <pre><code>process1 = new QProcess();
  </code></pre>
  
  <p>it works fine. Now i have a situation where i have many of these processes to be started. One option is to declare all of them as member functions:</p>
  
  <pre><code>QProcess* p1;
  QProcess* p2;
  QProcess* p3;
  ...
  </code></pre>
  
  <p>And then initialize all of them when needed. However this is too much redundant work. So i tried to create a list and initialize it in a loop like this:</p>
  
  <pre><code>QList&lt;QProcess*&gt; procList;
  
  for(int i=0; i&lt;len; i++){
     procList[i] = new QProcess();
  }
  </code></pre>
  
  <p>It compiles fine but then crashes. Is there something missing or what am i doing wrong here?</p>
  
  <p>I also tried to add all member variables in this list like:</p>
  
  <pre><code>   for(int i=0; i&lt;len; i++){
         switch(i){
            case 0:
               procList[i] = p1;
               break;
         }
  
      }
  </code></pre>
  
  <p>But this also has the same result like above</p>
  
  <p>EDIT:</p>
  
  <p>Based on your suggestion, i tried:</p>
  
  <pre><code>procList.append(new QProcess());
  </code></pre>
  
  <p>as well as <code>procList.append(p1);</code></p>
  
  <p>But result is same, it compiles but crashes at run time</p>
  
  <p><strong>EDIT:</strong>
  So i found the issue was totally unrelated. The class itself where i was using this code (custom class i made) had no default constructor. And as i learned without default constructor, if you initialize a pointer, somehow it just crashes.... strange. After specifying default constructor it is working fine now.</p>