Results 1 to 5 of 5

Thread: problem with QString and QsharedData

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

    Exclamation problem with QString and QsharedData

    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:perator=(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 attachmentrdci.tar.gz

    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

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: problem with QString and QsharedData

    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.

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

    Default Re: problem with QString and QsharedData

    Quote Originally Posted by ChrisW67 View Post
    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.

  4. #4
    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 

  5. #5
    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, 22:33
  2. problem in QString
    By wagmare in forum Qt Programming
    Replies: 4
    Last Post: 23rd December 2008, 13:28
  3. Replies: 4
    Last Post: 31st January 2008, 20:44
  4. QSharedData - implicit sharing
    By gyre in forum Newbie
    Replies: 4
    Last Post: 28th October 2007, 19:09
  5. QString problem
    By vermarajeev in forum Qt Programming
    Replies: 9
    Last Post: 26th October 2006, 19: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.