Reputation: 133
For a logging feature using ROS rqt+Qt4 I am trying to write to multiple files in a hardcoded folder hierarchy.
I have a parent class inheriting from QtWidget holding multiple QFile* members. I then assign them storage with *filehandle = new QFile(this).
Writing to the files works fine, but if I try to even set the Filename on the filehandles for reading the logfiles, I get an immediate Segmentation fault. However, not for all of the files I can see no consistent pattern in what file paths are affected.
Upvotes: 0
Views: 736
Reputation: 1
I got the same error i was declaring QFile as a private variable inside my class.
QFile archivo_pattern_bin;
then using it to open an hex file in the indicated absolute path
archivo_pattern_bin.setFileName(pattern_file_path);
archivo_pattern_bin.open(QIODevice::ReadWrite);
archivo_pattern_bin.flush();
this returned the windows segmentation error when debugging exactly at setFileName()
But now im just declaring a pointer
QFile * archivo_pattern_bin;
and creating the Qfile object dynamically
archivo_pattern_bin = new QFile(this);
archivo_pattern_bin->setFileName(pattern_file_path);
archivo_pattern_bin->open(QIODevice::ReadWrite);
archivo_pattern_bin->flush();
Also i was writting an array outside its defined size thus corrupting everything.......
and everything is alright now :D thanks pablo
Upvotes: 0
Reputation: 31
Some code would help.
From what I can see, the result of the new is a *QFile that should be assigned to another *QFile
QFile * filehandle;
*filehandle = new QFile(this) //is wrong
filehandle = new QFile(this) //is right
Remember that segmentation faults come from access to memory that has not been correctly reserved or that have been fred early with a delete statement.
If you stuck to much in a segmentation fault problem a quick way to know where is the problem is to run your program with a debugger (gdb). If you use QT Creator the process is really easy.
Upvotes: 1