yamen ajjour
21st August 2011, 14:57
Hi guys i've created two classes one called
circle
class circle
{
public:
circle();
QString name ;
int id ;
};
and another use this
class soso
{
public:
soso();
QList<circle*> lis;
void go();
};
in the constructor of soso i've just added two circle
soso::soso()
{
circle* c1 = new circle();
circle* c2= new circle();
c1->id=1;
c1->name="gimy";
c2->id=2;
c2->name="susana";
lis.append(c1);
lis.append(c2);
}
and in the main window i've called go method which is included here
void soso::go()
{
QFile file("database.txt");
if(!file.open(QIODevice::WriteOnly))
throw " cannot open file ! ";
QDataStream out(&file);
int i=0;
QList<circle*>::iterator it1 =lis.begin();
for(i=0;it1!=lis.end();it1++);
{
out<<(*it1)->id; // segmentation error in the runtime
out<<(*it1)->name;
}
}
but i am getting segmentation error any body know why ?
circle
class circle
{
public:
circle();
QString name ;
int id ;
};
and another use this
class soso
{
public:
soso();
QList<circle*> lis;
void go();
};
in the constructor of soso i've just added two circle
soso::soso()
{
circle* c1 = new circle();
circle* c2= new circle();
c1->id=1;
c1->name="gimy";
c2->id=2;
c2->name="susana";
lis.append(c1);
lis.append(c2);
}
and in the main window i've called go method which is included here
void soso::go()
{
QFile file("database.txt");
if(!file.open(QIODevice::WriteOnly))
throw " cannot open file ! ";
QDataStream out(&file);
int i=0;
QList<circle*>::iterator it1 =lis.begin();
for(i=0;it1!=lis.end();it1++);
{
out<<(*it1)->id; // segmentation error in the runtime
out<<(*it1)->name;
}
}
but i am getting segmentation error any body know why ?