PDA

View Full Version : problem with QString and QsharedData



jrch2k10
6th July 2011, 22:15
hi folkz im trying for a new project for first time Qt 4.7 (was used to 3.x) and i thought in using smart pointers but whatever i try i get this

#0 0x00007ffff66c865d in QString::operator=(QString const&) () from /usr/lib/libQtCore.so.4
#1 0x00007ffff7bd9631 in RDCI::RDebug::append (this=0x7fffffffe000, value=..., varname=..., linenumber=@0x7fffffffe060, filename=...,
sourcelocation=...) at rdcitypes.cpp:28
#2 0x0000000000401324 in main (argc=1, argv=0x7fffffffe178) at ../rdcitest/main.cpp:11


here is my source code as an attachment6638

in the main.cpp i tried several form from normal pointers to smart pointers and qstring break always there, probably is something stupid but i just don't see it

my os info
kubuntu natty 11.04
kde 4.6.4
qt 4.7.2 latest update
kernel 3.0.0 rc-6 preemp and no preemt just in case ;)

thx in advance for any help

ChrisW67
6th July 2011, 23:07
Your RDebug constructors never allocate an RDebugData object for your private data. As soon as you access the uninitialised d pointer... BOOM. Take a closer look at the Employee constructors in the example from the QSharedDataPointer docs.

BTW: gzipping an already gzipped tar file makes your archive tricky to extract.

jrch2k10
7th July 2011, 14:50
Your RDebug constructors never allocate an RDebugData object for your private data. As soon as you access the uninitialised d pointer... BOOM. Take a closer look at the Employee constructors in the example from the QSharedDataPointer docs.

BTW: gzipping an already gzipped tar file makes your archive tricky to extract.

it make sense now, i feel stupid lol. ill try later

thx for your answer

weird it should be a .tar.gz i don't know why it gzipped the file twice, maybe a bug in dolphin ark plugin. ill check that later.

jrch2k10
11th July 2011, 22:27
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>::~QSharedDataPointer (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[])
{
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;
}

rdcitypes_p.hpp

#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

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();
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


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 */

jrch2k10
12th July 2011, 14:45
it seems i forgot to clean my build, so at the end it only crash with float not with double, checking the source code it seems qvariant don't support float variables