Results 1 to 3 of 3

Thread: std::cout displaying a hex value instead of a string.

  1. #1
    Join Date
    Feb 2006
    Posts
    47
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Cool std::cout displaying a hex value instead of a string.

    I wanted to dump some QStrings to the console. I am using the following code:

    Qt Code:
    1. std::cout<<"#"<<Item_Parent->child(i)->data(DB_SERIES__PATH,Qt::DisplayRole).toString().constData()<<"\n";
    To copy to clipboard, switch view to plain text mode 

    It seems fine but I get the following at the console:
    Qt Code:
    1. #0x815b8aa
    2. #0x816ee42
    3. #0x8175eb2
    To copy to clipboard, switch view to plain text mode 

    I want to see the string. I thought constData() would work, but it seems like cout is not processing it right. Suggestions?

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: std::cout displaying a hex value instead of a string.

    try toStdString()

  3. The following user says thank you to munna for this useful post:

    johnny_sparx (7th April 2006)

  4. #3
    Join Date
    Jan 2006
    Posts
    109
    Thanks
    2
    Thanked 5 Times in 5 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: std::cout displaying a hex value instead of a string.

    Try this:
    Qt Code:
    1. #include <QString>
    2. #include <iostream>
    3. int main() {
    4. const QString s("test 1234567890");
    5. std::cout << s.constData() << std::endl; // returns QChar *
    6. std::cout << s.toAscii().constData() << std::endl; // returns char *
    7. }
    To copy to clipboard, switch view to plain text mode 
    and have a look at QString::constData() vs. QByteArray::constData().

Similar Threads

  1. Replies: 0
    Last Post: 18th February 2009, 13:31
  2. Reading from sockets in a multithreaded program
    By KoosKoets in forum Qt Programming
    Replies: 9
    Last Post: 4th April 2007, 20:43
  3. saving a c string of variable length in a shared memory?
    By nass in forum General Programming
    Replies: 4
    Last Post: 3rd January 2007, 14:40

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.