Results 1 to 3 of 3

Thread: HOW CAN I INPUT A QString IN THE CONSOLE

  1. #1
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default HOW CAN I INPUT A QString IN THE CONSOLE

    Hi everyone, How can I input a QString in the console? In short i've got a QString variable in my program which I want to input a string in. If it was an STL string I would have used the function getline() but I'm not sure which function to use with QString. please help.

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: HOW CAN I INPUT A QString IN THE CONSOLE

    You still can use getline with conjunction of std::string::c_str and pass this value to QString's ctor.
    Qt Code:
    1. ...
    2. std::string str;
    3. std::getline(std::cin, str);
    4. QString qString(str.c_str());
    5. qDebug() << qString;
    6. ...
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: HOW CAN I INPUT A QString IN THE CONSOLE

    A whole line:
    Qt Code:
    1. QTextStream s(stdin);
    2. QString value = s.readLine();
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 2
    Last Post: 11th August 2011, 15:42
  2. User Input using QString
    By kumarpraveen in forum Newbie
    Replies: 4
    Last Post: 9th July 2010, 07:49
  3. Console input with QCoreApplication
    By rahman.duran in forum Qt Programming
    Replies: 4
    Last Post: 25th February 2009, 10:37
  4. Replies: 4
    Last Post: 31st January 2008, 20:44
  5. Replies: 5
    Last Post: 24th July 2007, 17:35

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.