Results 1 to 5 of 5

Thread: problem with QString and QsharedData

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2011
    Location
    Caracas
    Posts
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: problem with QString and QsharedData

    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
    Qt Code:
    1. #include <QtCore/QCoreApplication>
    2. #include "rdcitypes.hpp"
    3. int main(int argc, char *argv[])
    4. {
    5. QCoreApplication a(argc, argv);
    6. using namespace std;
    7. using namespace RDCI;
    8. QString var = "hola";
    9. float var2 = 500;
    10. RDebug prueba;
    11. cout << prueba.saveValues(var2) << endl;
    12. cout << prueba.getSourceLocation().toStdString() << endl;
    13. cout << prueba.getSize() << endl;
    14. return 0;
    15. }
    To copy to clipboard, switch view to plain text mode 

    rdcitypes_p.hpp
    Qt Code:
    1. #ifndef RDCITYPES_P_H
    2. #define RDCITYPES_P_H
    3.  
    4. #include "definitions.hpp"
    5.  
    6. namespace RDCI
    7. {
    8. class SO_LOCAL RDebugData : public QSharedData
    9. {
    10. public:
    11. RDebugData()
    12. {}
    13. RDebugData(const RDebugData &other)
    14. : QSharedData(other), fileName(other.fileName), sourceLocation(other.sourceLocation), varName(other.varName), lineNumber(other.lineNumber), Value(other.Value), size(other.size)
    15. { }
    16. ~RDebugData()
    17. {}
    18. QString fileName, sourceLocation, varName;
    19. quint64 lineNumber, size;
    20. QVariant Value;
    21. };
    22. }
    23. #endif
    To copy to clipboard, switch view to plain text mode 

    rdcitypes.hpp
    Qt Code:
    1. #ifndef RDCITYPES_H
    2. #define RDCITYPES_H
    3.  
    4. #include "rdcitypes_p.hpp"
    5.  
    6. namespace RDCI
    7. {
    8. class RDebugData;
    9. class SO_PUBLIC RDebug
    10. {
    11. public:
    12. RDebug()
    13. {
    14. d = new RDebugData;
    15. }
    16. RDebug(const RDebug &other): d (other.d)
    17. {}
    18. virtual ~RDebug();
    19. bool isEmpty();
    20. QVariant getValue() const
    21. {
    22. return d->Value;
    23. }
    24. QString getFileName() const
    25. {
    26. return d->fileName;
    27. }
    28. QString getSourceLocation() const
    29. {
    30. return d->sourceLocation;
    31. }
    32. QString getVarName() const
    33. {
    34. return d->varName;
    35. }
    36. quint64 getLineNumber() const
    37. {
    38. return d->lineNumber;
    39. }
    40. quint64 getSize() const
    41. {
    42. return d->size;
    43. }
    44. template <typename U>
    45. U saveValues_p(U const &value, const QString &varname, quint64 linenumber, const QString &filename, const QString &sourcelocation, const quint64 size)
    46. {
    47. d->varName = varname;
    48. d->lineNumber = linenumber;
    49. d->fileName = filename;
    50. d->sourceLocation = sourcelocation;
    51. d->Value = value;
    52. d->size = size;
    53. return value;
    54. }
    55. private:
    56. QSharedDataPointer<RDebugData> d;
    57. };
    58.  
    59. }
    60. #endif // RDCITYPES_H
    To copy to clipboard, switch view to plain text mode 

    definition.hpp
    Qt Code:
    1. ifndef DEFINITIONS_H
    2. #define DEFINITIONS_H
    3.  
    4. #include <QtPlugin>
    5. #include <QObject>
    6. #include <QMetaType>
    7. #include <QSharedData>
    8. #include <QSharedDataPointer>
    9. #include <QtCore/QVariant>
    10. #include <QtDBus/QDBusConnection>
    11. #include <QtDBus/QDBusMessage>
    12. #include <QtDBus/QtDBus>
    13. #include <QtCore/QList>
    14.  
    15. #include <sys/types.h>
    16. #include <iostream>
    17. #include <algorithm>
    18.  
    19. namespace RDCI
    20. {
    21.  
    22. #if __GNUC__ >= 4
    23. #define SO_PUBLIC __attribute__ ((visibility("default")))
    24. #define SO_LOCAL __attribute__ ((visibility("hidden")))
    25. #define saveValues(value) \
    26. saveValues_p( value, #value, __LINE__, __FILE__, __PRETTY_FUNCTION__, sizeof(value))
    27. #endif
    28. }
    29. #endif /* DEFINITIONS_H */
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jun 2011
    Location
    Caracas
    Posts
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: problem with QString and QsharedData

    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

Similar Threads

  1. QsharedMemory or QsharedData ?
    By OverTheOCean in forum Qt Programming
    Replies: 2
    Last Post: 7th November 2010, 23:33
  2. problem in QString
    By wagmare in forum Qt Programming
    Replies: 4
    Last Post: 23rd December 2008, 14:28
  3. Replies: 4
    Last Post: 31st January 2008, 21:44
  4. QSharedData - implicit sharing
    By gyre in forum Newbie
    Replies: 4
    Last Post: 28th October 2007, 20:09
  5. QString problem
    By vermarajeev in forum Qt Programming
    Replies: 9
    Last Post: 26th October 2006, 20:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.