Results 1 to 5 of 5

Thread: QString assignment

  1. #1
    Join Date
    Mar 2010
    Location
    spain
    Posts
    25
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QString assignment

    Qt Code:
    1. class TagAudio
    2. {
    3. private:
    4.  
    5.  
    6.  
    7. protected:
    8.  
    9. public:
    10.  
    11. QString TagNombre;
    12. TagAudio();
    13. void Iniciar(const char *file );
    14.  
    15.  
    16.  
    17.  
    18. };
    19.  
    20.  
    21. TagAudio::TagAudio()
    22. {
    23.  
    24.  
    25. }
    26.  
    27.  
    28.  
    29. void TagAudio::Iniciar(const char *file){
    30.  
    31. TagLib::FileRef tagFile(file);
    32. if(!tagFile.isNull()){
    33.  
    34.  
    35. QString TagTmp;
    36. TagTmp = TStringToQString(tagFile.tag()->album()); //yes
    37. TagNombre = TStringToQString(tagFile.tag()->album()); //no ?
    38.  
    39.  
    40.  
    41. }
    42.  
    43.  
    44.  
    45.  
    46. }
    To copy to clipboard, switch view to plain text mode 

    For the second assignment is not possible TagNombre
    thanks

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QString assignment

    what error message do you get?

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QString assignment

    ... and how is TStringToQString defined?

  4. #4
    Join Date
    Mar 2010
    Location
    spain
    Posts
    25
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QString assignment

    Qt Code:
    1. #ifndef TAGAUDIO_H
    2. #define TAGAUDIO_H
    3.  
    4. #include <QString>
    5.  
    6. #include "fileref.h"
    7. #include "tag.h"
    8. #include "tbytevector.h"
    9. #include "taglib_export.h"
    10.  
    11.  
    12. class TagAudio
    13. {
    14. private:
    15.  
    16.  
    17.  
    18. protected:
    19.  
    20. public:
    21.  
    22.  
    23. TagAudio();
    24. void Iniciar(const char *file );
    25. QString TagNombre;
    26.  
    27.  
    28.  
    29. };
    30.  
    31.  
    32.  
    33. #endif // TAGAUDIO_H
    34.  
    35.  
    36.  
    37. #include <iostream>
    38. #include <stdio.h>
    39.  
    40. #include <QDebug>
    41. #include <QString>
    42. #include <QMessageBox>
    43. #include <QByteArray>
    44. #include <QFile>
    45.  
    46. #include "fileref.h"
    47. #include "tag.h"
    48. #include "tbytevector.h"
    49. #include "TagAudio.h"
    50. #include "taglib_export.h"
    51.  
    52. using namespace std;
    53.  
    54.  
    55. TagAudio::TagAudio()
    56. {
    57.  
    58.  
    59. }
    60.  
    61.  
    62.  
    63. void TagAudio::Iniciar(const char *file){
    64.  
    65.  
    66.  
    67.  
    68. TagLib::FileRef tagFile(file);
    69. if(!tagFile.isNull()){
    70.  
    71. TagNombre=TStringToQString(tagFile.tag()->album()); // causes CRASH application ?
    72.  
    73.  
    74. qDebug() << "salida" << TStringToQString(tagFile.tag()->album()); //perfect start
    75.  
    76.  
    77.  
    78. }
    79.  
    80.  
    81.  
    82.  
    83. }
    To copy to clipboard, switch view to plain text mode 


    TagNombre=TStringToQString(tagFile.tag()->album()); // causes CRASH application ?
    Last edited by valgaba; 25th April 2010 at 17:47.

  5. #5
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QString assignment

    There's probably a temporary class object being created somewhere which is being freed on the return and so your line is dereferencing freed memory. Try and seperate it out a bit more (eg. assign the tag()->album first, and then use TStringToQString)

Similar Threads

  1. Replies: 4
    Last Post: 31st January 2008, 21:44
  2. QVector assignment question
    By hvw59601 in forum Qt Programming
    Replies: 1
    Last Post: 14th November 2007, 21:34
  3. Do assignment operators in Qt4 return deep or shallow copy?
    By high_flyer in forum Qt Programming
    Replies: 5
    Last Post: 25th September 2006, 10:01
  4. copying and assignment constructors
    By TheKedge in forum General Programming
    Replies: 3
    Last Post: 17th August 2006, 16:09
  5. QMap <int, QGuardedPtr<Employee> > Crashes on Assignment ???
    By sunil.thaha in forum Qt Programming
    Replies: 2
    Last Post: 16th March 2006, 08:09

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.