11-30-2012 08:13 AM
I spent some fruitless hours yesterday hunting down a segfault.
As far as i have understood this it is similar to a nullpointerexception in java.
I have narrowed it down to a few lines of code - when i comment them out the segfault is gone - but i have no clue why it occurs there, as i check every pointer i use for being null.
When i use the debugger, it points to a setter with QString, with the message
"QString:
perator=() at 0x..."
Not sure if the code is helpful, but i just take the chance:
objectValue is a QString, setFormula is a simple setter
qDebug() << "enabledformula value: " << objectValue;
DataServiceFormula* dsFormula = buttonInput->getEnabledFormula(); qDebug() << "after retrieving formula"; if (!dsFormula) { qDebug() << "formula is null"; dsFormula = new DataServiceFormula(); } qDebug() << "setting formula"; QString formulaString = objectValue.toLower().trimmed(); qDebug() << "to " << formulaString; dsFormula->setFormula(formulaString); qDebug() << "set formula successful";
And the debugger creates this output:
Debug: enabledformula value: "C1" Debug: after retrieving formula Debug: setting formula Debug: to "c1"
After that comes the SIGSEGV
Any general ideas how i could find out why it occurs?
Solved! Go to Solution.
11-30-2012 09:25 AM
To try to answer this we need to know declaration and definition of
dsFormula->setFormula()
and dsFormula class itself. I does not look like it is some standard class.
12-03-2012 03:55 AM
it is a very simple bean class.
header:
/*
* DataServiceFormula.hpp
*
* Created on: 06.09.2012
* Author: sha
*/
#ifndef DATASERVICEFORMULA_HPP_
#define DATASERVICEFORMULA_HPP_
#include "DataServiceCondition.hpp"
#include <QHash>
#include <QString>
#include <qobject.h>
class DataServiceFormula: public QObject {
Q_OBJECT
private:
QString formula;
QHash<QString, DataServiceCondition*> conditions;
QString errorText;
public:
enum DataServiceFormulaType {
DataServiceFormulaTypeMandatory = 1,
DataServiceFormulaTypeReadonly = 2,
DataServiceFormulaTypeVisible = 3,
DataServiceFormulaTypeEnabled = 4,
DataServiceFormulaTypeValidation = 5
};
QHash<QString, DataServiceCondition*> getConditions() const;
void setConditions(QHash<QString, DataServiceCondition*> conditions);
QString getFormula() const;
void setFormula(QString formula);
QString getErrorText() const;
void setErrorText(QString errorText);
};
#endif /* DATASERVICEFORMULA_HPP_ */
cpp:
/*
* DataServiceFormula.cpp
*
* Created on: 06.09.2012
* Author: sha
*/
#include "DataServiceFormula.hpp"
#include <QHash>
#include <QString>
QHash<QString, DataServiceCondition*> DataServiceFormula::getConditions() const {
return conditions;
}
void DataServiceFormula::setConditions(QHash<QString, DataServiceCondition*> conditions) {
this->conditions = conditions;
}
QString DataServiceFormula::getFormula() const {
return formula;
}
QString DataServiceFormula::getErrorText() const {
return errorText;
}
void DataServiceFormula::setErrorText(QString errorText) {
this->errorText = errorText;
}
void DataServiceFormula::setFormula(QString formula) {
this->formula = formula;
}
12-03-2012 04:19 AM
First thing that comes to my mind is variable shadowin issue, but maybe I'm wrong
void DataServiceFormula::setFormula(QString fParam) {
this->formula = fParam;
}
12-03-2012 04:21 AM
12-03-2012 09:02 AM
so far everything looks correct. (by the way you can completely remove this-> in your clas member functions).
Now we need to see how DataServiceFormula object is constructed/created.
DataServiceFormula* dsFormula = buttonInput->getEnabledFormula();
can you post buttonInput->getEnabledFormula() implementation and related stuff please?
12-03-2012 09:15 AM
12-03-2012 09:18 AM
where is this 'below'? -)
12-03-2012 09:26 AM
Here is the part again. It is called in a loop where i iterate attributes from the webservice.
objectValue is a QString, populated from the soap response.
qDebug() << "enabledformula value: " << objectValue;
if (!buttonInput){
qDebug() << "buttonInput is null";
}
DataServiceFormula* dsFormula = buttonInput->getEnabledFormula();
qDebug() << "after retrieving formula";
if (!dsFormula) {
qDebug() << "creating new formula";
dsFormula = new DataServiceFormula();
buttonInput->setEnabledFormula(dsFormula);
}
qDebug() << "setting formula";
QString formulaString = objectValue.toLower().trimmed();
qDebug() << "to " << formulaString; dsFormula->setFormula(formulaString);
qDebug() << "set formula successful";
And the console output when i run it:
Debug: enabledformula value: "C1" Debug: after retrieving formula Debug: setting formula Debug: to "c1" Process 80048308 (bb10) terminated SIGSEGV code=1 fltno=11 ip=78e8f182(/base/usr/lib/qt4/lib/libQtCore.so.4.8.4@_ZN7QStringaSERKS_+0x19) mapaddr=0008f182. ref=6f63636d
12-03-2012 09:29 AM
hope somebody else will be able to help you. Good luck with hunting.