Results 1 to 5 of 5

Thread: QString to char*

  1. #1
    Join Date
    Mar 2008
    Location
    Morocco
    Posts
    47
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QString to char*

    Hi..
    I would like to know if there is a methode in Qt that converts a QString to char* ??

    thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Knivsta, Sweden
    Posts
    153
    Thanks
    30
    Thanked 13 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QString to char*

    qPrintable()

  3. #3

    Default Re: QString to char*

    Qt Code:
    1. QString convertString;
    2. const char *errorMessage = converString.toAscii().constData();
    3. char *errorMessage = convertString.toAscii().data();
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QString to char*

    Quote Originally Posted by litroncn View Post
    Qt Code:
    1. QString convertString;
    2. const char *errorMessage = converString.toAscii().constData();
    3. char *errorMessage = convertString.toAscii().data();
    To copy to clipboard, switch view to plain text mode 
    Happy crashing when you want to access errorMessage later

  5. #5
    Join Date
    Aug 2006
    Posts
    77
    Thanks
    14
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QString to char*

    QString convertString;

    QByteArray ba = converString.toLatin1();
    char *errorMessage = ba.data();

    Never use direct conversion : converString.toLatin1().data()

Similar Threads

  1. easiest Way QString can do
    By baray98 in forum Qt Programming
    Replies: 12
    Last Post: 15th April 2008, 20:49
  2. QString static callback function from CURL
    By tpf80 in forum Qt Programming
    Replies: 12
    Last Post: 16th May 2007, 20:47
  3. Problem in converting QString to QChar array?
    By KaKa in forum Qt Programming
    Replies: 2
    Last Post: 19th March 2007, 00:38
  4. Convert from iso-8859-1 to... Something else :-)
    By Nyphel in forum Qt Programming
    Replies: 4
    Last Post: 7th March 2007, 17:59
  5. QSqlQueryModel + set Write
    By raphaelf in forum Qt Programming
    Replies: 7
    Last Post: 5th June 2006, 08: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.