Results 1 to 5 of 5

Thread: problem in QString

  1. #1
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Post problem in QString

    hi friends,

    Qt Code:
    1. const char *str;
    2. QString path;
    3. path = lineEdit->text();
    4. [B]str = (const char *)path.latin1();[/B]
    5. // [B]str = (const char *)path.local8Bit());[/B]
    To copy to clipboard, switch view to plain text mode 

    but compilation gives error: ‘class QString’ has no member named ‘latin1’
    or local8Bit() why its showing like this....
    please help ..

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

    Default Re: problem in QString

    well, it is showing that because...
    a) you are using Qt4 and that is simply the truth: there is no such method (there is QString::toLatin1(), though)
    b) you are using Qt3 and forgot to #include <QString>

    HTH

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: problem in QString

    QString::latin1() is Qt 3. In Qt 4 it's named a little bit different. Make sure to read the correct version of docs.
    J-P Nurmi

  4. The following user says thank you to jpn for this useful post:

    wagmare (23rd December 2008)

  5. #4
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem in QString

    first thanks for reply guru

    you are right i am using Qt4.4.3 .... i just follow one good example in net without considering
    version .....

  6. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: problem in QString

    Just notice that the example you've found is a bit problematic. QString::toLatin1() returns a QByteArray object. You store a pointer to the internal data of that temporary object. "const char* str" is a dangling pointer as soon as the QByteArray object goes out of scope. For more details, see TT knowledgebase: How can I convert a QString to char* and vice versa ?
    J-P Nurmi

Similar Threads

  1. QString problem?
    By raphaelf in forum Newbie
    Replies: 7
    Last Post: 24th June 2008, 09:12
  2. Problem in converting QString to QChar array?
    By KaKa in forum Qt Programming
    Replies: 2
    Last Post: 19th March 2007, 00:38
  3. Convert from iso-8859-1 to... Something else :-)
    By Nyphel in forum Qt Programming
    Replies: 4
    Last Post: 7th March 2007, 17:59
  4. QString problem
    By vermarajeev in forum Qt Programming
    Replies: 9
    Last Post: 26th October 2006, 19:10
  5. Problem with custom widget
    By jnana in forum Qt Programming
    Replies: 3
    Last Post: 15th March 2006, 11:55

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.