Results 1 to 5 of 5

Thread: std::string to QString?

  1. #1
    Join Date
    Jul 2007
    Posts
    23
    Thanks
    16
    Qt products
    Qt4
    Platforms
    Windows

    Question std::string to QString?

    Hello all,

    I'm trying to set the text of a QLabel, among other things, which takes QString. I need to set it however from the text in a std::string. How do I do this conversion? I've tried looking in the QString Class Reference to no avail...

    I was trying to use

    Qt Code:
    1. ui.labelName->setText(K1.getName());
    To copy to clipboard, switch view to plain text mode 

    but K1.getName(); returns std::string

    Thanks for the time,
    Backslash

  2. #2
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: std::string to QString?

    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

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

    Backslash (1st August 2007)

  4. #3
    Join Date
    Jul 2007
    Posts
    23
    Thanks
    16
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: std::string to QString?

    I don't suppose this is what you mean?

    Qt Code:
    1. ui.labelName->setText(QString::fromStdString ( const std::string & K1.getName() ));
    To copy to clipboard, switch view to plain text mode 

    Sorry if I'm missing something painfully simple

    Thanks,
    Backslash

  5. #4
    Join Date
    Jul 2007
    Posts
    23
    Thanks
    16
    Qt products
    Qt4
    Platforms
    Windows

    Exclamation Re: std::string to QString?

    Sorry stupid move. I suppose I should be using:

    ui.labelName->setText(QString::fromStdString (K1.getName()));

  6. #5
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: std::string to QString?

    No, I mean this:

    Qt Code:
    1. ui.labelName->setText(QString::fromStdString( K1.getName() ));
    To copy to clipboard, switch view to plain text mode 

    In my previous post I gave the function signature (this included the type of the parameter).

    Edit: Yep, you got it.
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

  7. The following user says thank you to Michiel for this useful post:

    Backslash (1st August 2007)

Similar Threads

  1. QString static callback function from CURL
    By tpf80 in forum Qt Programming
    Replies: 12
    Last Post: 16th May 2007, 21:47
  2. Convert from iso-8859-1 to... Something else :-)
    By Nyphel in forum Qt Programming
    Replies: 4
    Last Post: 7th March 2007, 18:59
  3. QString problem
    By vermarajeev in forum Qt Programming
    Replies: 9
    Last Post: 26th October 2006, 20:10
  4. Converting QString to unsigned char
    By salston in forum Qt Programming
    Replies: 3
    Last Post: 24th April 2006, 23:10
  5. [SOLVED] Widget plugin ... how to ?
    By yellowmat in forum Newbie
    Replies: 10
    Last Post: 29th January 2006, 21:41

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.