The code :
.h
#include <vector>
using namespace std;
bool callVector(vector<float>&);
void func();
vector <float> vectorname;
float v;
#include <vector>
using namespace std;
bool callVector(vector<float>&);
void func();
vector <float> vectorname;
QString filename = "vector.txt";
QFile file(filename);
QString val;
float v;
To copy to clipboard, switch view to plain text mode
.cpp
void myClass::func(){
if(!callVector(vectorname))
{
qDebug() << " vector error" ;
}
else
{
qDebug()<<"vector success" ;
}
{
for ( int i =0; i<vectorname.size() ; i++)
{
v = vectorname.at(i); //system crash here
qDebug()<< "val" << val;
char *valtoAsciidata = val.toAscii().data();
file.write(valtoAsciidata);
}
qDebug()<<"front =" << vectorname.front();
qDebug()<<"back =" << vectorname.back();
qDebug()<< "vector write finish!:" << "success";
file.close();
}
else
{
qDebug()<<"error write vector.txt file";
}
}
void myClass::func(){
if(!callVector(vectorname))
{
qDebug() << " vector error" ;
}
else
{
qDebug()<<"vector success" ;
}
if (file.open(QIODevice::WriteOnly | QIODevice::Truncate))
{
for ( int i =0; i<vectorname.size() ; i++)
{
v = vectorname.at(i); //system crash here
val = QString::number(v);
qDebug()<< "val" << val;
char *valtoAsciidata = val.toAscii().data();
file.write(valtoAsciidata);
}
qDebug()<<"front =" << vectorname.front();
qDebug()<<"back =" << vectorname.back();
qDebug()<< "vector write finish!:" << "success";
file.close();
}
else
{
qDebug()<<"error write vector.txt file";
}
}
To copy to clipboard, switch view to plain text mode
The system crash with error as below when debugging:
<Signal received>
The inferior stopped because it received a signal from the Operating System
Signal name : SIGSEGV
Signal meaning : Segmentation fault
The callVector is an API and it is called if dll is loaded. The code is in another program and the code is currently not transparent to me.
The qDebug() returns "vector success" message when callVector is called in my program.
Bookmarks