In My class I have a member variable;
QProcess* p1;
Inside some function, i initialize and use it as:
process1 = new QProcess();
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:
QProcess* p1;
QProcess* p2;
QProcess* p3;
...
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:
QList<QProcess*> procList;
for(int i=0; i<len; i++){
procList[i] = new QProcess();
}
It compiles fine but then crashes. Is there something missing or what am i doing wrong here?
I also tried to add all member variables in this list like:
for(int i=0; i<len; i++){
switch(i){
case 0:
procList[i] = p1;
break;
}
}
But this also has the same result like above
EDIT:
Based on your suggestion, i tried:
procList.append(new QProcess());
as well as procList.append(p1);
But result is same, it compiles but crashes at run time
EDIT: 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.