chris all is working as it should now, you were right but i found some weird behavior.
everytime i pass float types or double or long double, etc qvariant class emit a crash, i tried with almost any other type including QT ones and it work perfectly it just crash with floating point values
here is the back trace
#0 0x00007ffff6787383 in QVariant::~QVariant() () from /usr/lib/libQtCore.so.4
#1 0x00007ffff7bd9935 in RDCI::RDebugData::~RDebugData (this=0x60a940, __in_chrg=<value optimized out>) at rdcitypes_p.hpp:9
#2 0x00007ffff7bd9a07 in QSharedDataPointer<RDCI::RDebugData>::~QSharedData Pointer (this=0x7fffffffe008,
__in_chrg=<value optimized out>) at /usr/include/qt4/QtCore/qshareddata.h:90
#3 0x00007ffff7bd938e in RDCI::RDebug::~RDebug (this=0x7fffffffe000, __in_chrg=<value optimized out>) at rdcitypes.cpp:5
#4 0x000000000040189e in main (argc=1, argv=0x7fffffffe178) at ../rdcitest/main.cpp:10
my code
main.cpp
#include <QtCore/QCoreApplication>
#include "rdcitypes.hpp"
int main(int argc, char *argv[])
{
using namespace std;
using namespace RDCI;
float var2 = 500;
RDebug prueba;
cout << prueba.saveValues(var2) << endl;
cout << prueba.getSourceLocation().toStdString() << endl;
cout << prueba.getSize() << endl;
return 0;
}
#include <QtCore/QCoreApplication>
#include "rdcitypes.hpp"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
using namespace std;
using namespace RDCI;
QString var = "hola";
float var2 = 500;
RDebug prueba;
cout << prueba.saveValues(var2) << endl;
cout << prueba.getSourceLocation().toStdString() << endl;
cout << prueba.getSize() << endl;
return 0;
}
To copy to clipboard, switch view to plain text mode
rdcitypes_p.hpp
#ifndef RDCITYPES_P_H
#define RDCITYPES_P_H
#include "definitions.hpp"
namespace RDCI
{
{
public:
RDebugData()
{}
RDebugData(const RDebugData &other)
: QSharedData(other
), fileName
(other.
fileName), sourceLocation
(other.
sourceLocation), varName
(other.
varName), lineNumber
(other.
lineNumber), Value
(other.
Value), size
(other.
size) { }
~RDebugData()
{}
QString fileName, sourceLocation, varName;
quint64 lineNumber, size;
};
}
#endif
#ifndef RDCITYPES_P_H
#define RDCITYPES_P_H
#include "definitions.hpp"
namespace RDCI
{
class SO_LOCAL RDebugData : public QSharedData
{
public:
RDebugData()
{}
RDebugData(const RDebugData &other)
: QSharedData(other), fileName(other.fileName), sourceLocation(other.sourceLocation), varName(other.varName), lineNumber(other.lineNumber), Value(other.Value), size(other.size)
{ }
~RDebugData()
{}
QString fileName, sourceLocation, varName;
quint64 lineNumber, size;
QVariant Value;
};
}
#endif
To copy to clipboard, switch view to plain text mode
rdcitypes.hpp
#ifndef RDCITYPES_H
#define RDCITYPES_H
#include "rdcitypes_p.hpp"
namespace RDCI
{
class RDebugData;
class SO_PUBLIC RDebug
{
public:
RDebug()
{
d = new RDebugData;
}
RDebug(const RDebug &other): d (other.d)
{}
virtual ~RDebug();
bool isEmpty();
{
return d->Value;
}
{
return d->fileName;
}
{
return d->sourceLocation;
}
{
return d->varName;
}
quint64 getLineNumber() const
{
return d->lineNumber;
}
quint64 getSize() const
{
return d->size;
}
template <typename U>
U saveValues_p
(U
const &value,
const QString &varname, quint64 linenumber,
const QString &filename,
const QString &sourcelocation,
const quint64 size
) {
d->varName = varname;
d->lineNumber = linenumber;
d->fileName = filename;
d->sourceLocation = sourcelocation;
d->Value = value;
d->size = size;
return value;
}
private:
QSharedDataPointer<RDebugData> d;
};
}
#endif // RDCITYPES_H
#ifndef RDCITYPES_H
#define RDCITYPES_H
#include "rdcitypes_p.hpp"
namespace RDCI
{
class RDebugData;
class SO_PUBLIC RDebug
{
public:
RDebug()
{
d = new RDebugData;
}
RDebug(const RDebug &other): d (other.d)
{}
virtual ~RDebug();
bool isEmpty();
QVariant getValue() const
{
return d->Value;
}
QString getFileName() const
{
return d->fileName;
}
QString getSourceLocation() const
{
return d->sourceLocation;
}
QString getVarName() const
{
return d->varName;
}
quint64 getLineNumber() const
{
return d->lineNumber;
}
quint64 getSize() const
{
return d->size;
}
template <typename U>
U saveValues_p(U const &value, const QString &varname, quint64 linenumber, const QString &filename, const QString &sourcelocation, const quint64 size)
{
d->varName = varname;
d->lineNumber = linenumber;
d->fileName = filename;
d->sourceLocation = sourcelocation;
d->Value = value;
d->size = size;
return value;
}
private:
QSharedDataPointer<RDebugData> d;
};
}
#endif // RDCITYPES_H
To copy to clipboard, switch view to plain text mode
definition.hpp
ifndef DEFINITIONS_H
#define DEFINITIONS_H
#include <QtPlugin>
#include <QObject>
#include <QMetaType>
#include <QSharedData>
#include <QSharedDataPointer>
#include <QtCore/QVariant>
#include <QtDBus/QDBusConnection>
#include <QtDBus/QDBusMessage>
#include <QtDBus/QtDBus>
#include <QtCore/QList>
#include <sys/types.h>
#include <iostream>
#include <algorithm>
namespace RDCI
{
#if __GNUC__ >= 4
#define SO_PUBLIC __attribute__ ((visibility("default")))
#define SO_LOCAL __attribute__ ((visibility("hidden")))
#define saveValues(value) \
saveValues_p( value, #value, __LINE__, __FILE__, __PRETTY_FUNCTION__, sizeof(value))
#endif
}
#endif /* DEFINITIONS_H */
ifndef DEFINITIONS_H
#define DEFINITIONS_H
#include <QtPlugin>
#include <QObject>
#include <QMetaType>
#include <QSharedData>
#include <QSharedDataPointer>
#include <QtCore/QVariant>
#include <QtDBus/QDBusConnection>
#include <QtDBus/QDBusMessage>
#include <QtDBus/QtDBus>
#include <QtCore/QList>
#include <sys/types.h>
#include <iostream>
#include <algorithm>
namespace RDCI
{
#if __GNUC__ >= 4
#define SO_PUBLIC __attribute__ ((visibility("default")))
#define SO_LOCAL __attribute__ ((visibility("hidden")))
#define saveValues(value) \
saveValues_p( value, #value, __LINE__, __FILE__, __PRETTY_FUNCTION__, sizeof(value))
#endif
}
#endif /* DEFINITIONS_H */
To copy to clipboard, switch view to plain text mode
Bookmarks