Results 1 to 5 of 5

Thread: User Input using QString

  1. #1
    Join Date
    Jun 2010
    Posts
    7
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default User Input using QString

    In C/C++ when i defined a string i can use scanf("%s",str_name) for user input, but if i want to defined a QString and use same function for getting user input , it fails
    Qt Code:
    1. .....
    2. QString username;
    3. scanf("%s",username); //not work give a warning
    To copy to clipboard, switch view to plain text mode 

    thanks in advance

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: User Input using QString

    Can you tell what does "%s" signify ??
    Would %s work with integers ?

    Secondly if you are using Qt, I would suggest go for gui method of input rather than console.

    Thirdly, if you want to use C++, better use cin >> someString;

  3. #3
    Join Date
    Jun 2010
    Posts
    7
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: User Input using QString

    Quote Originally Posted by aamer4yu View Post
    Can you tell what does "%s" signify ??
    Would %s work with integers ?
    no it works with strings.
    Quote Originally Posted by aamer4yu View Post
    Secondly if you are using Qt, I would suggest go for gui method of input rather than console.
    i am using console input for testing purpose after that i go for Gui.
    Quote Originally Posted by aamer4yu View Post
    Thirdly, if you want to use C++, better use cin >> someString;
    ok. thanks

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: User Input using QString

    no it works with strings
    So how do you expect it to work with QString of which it has no knowledge of ?
    I just asked to make you understand.

    Now you can do the following -
    char name[100];
    scanf("%s" name);
    QString qstring = name; // This will work because QString class knows to handle char data..

  5. #5
    Join Date
    Jun 2010
    Posts
    7
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: User Input using QString

    Quote Originally Posted by aamer4yu View Post
    So how do you expect it to work with QString of which it has no knowledge of ?
    I just asked to make you understand.

    Now you can do the following -
    char name[100];
    scanf("%s" name);
    QString qstring = name; // This will work because QString class knows to handle char data..
    now i am using QTextStream BTW thanks for that.

Similar Threads

  1. Make QDial ignore user input
    By burnchar in forum Qt Programming
    Replies: 4
    Last Post: 17th February 2010, 19:52
  2. problem with reading input from user
    By ketan007 in forum Qt Programming
    Replies: 1
    Last Post: 5th December 2009, 11:51
  3. Replies: 4
    Last Post: 24th July 2009, 09:48
  4. QSplitter only resize from user input?
    By winston2020 in forum Qt Programming
    Replies: 1
    Last Post: 30th January 2009, 16:50
  5. Discard user input events in QEventLoop.
    By Ben.Hines in forum Qt Programming
    Replies: 2
    Last Post: 17th April 2006, 21:49

Tags for this Thread

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.