PDA

View Full Version : User Input using QString



kumarpraveen
9th July 2010, 05:18
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 :(


.....
QString username;
scanf("%s",username); //not work give a warning


thanks in advance

aamer4yu
9th July 2010, 05:29
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;

kumarpraveen
9th July 2010, 06:11
Can you tell what does "%s" signify ??
Would %s work with integers ?
no it works with strings.

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.

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

aamer4yu
9th July 2010, 06:31
no it works with strings
So how do you expect it to work with QString of which it has no knowledge of ? :rolleyes:
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..

kumarpraveen
9th July 2010, 07:49
So how do you expect it to work with QString of which it has no knowledge of ? :rolleyes:
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.