PDA

View Full Version : unable to convert from one type to another



sachinmcajnu
15th March 2011, 17:23
hi as i am new to qt ...but from c/c++ background i know how to typecast from one type to another
but here i am seriously facing problem in this

eg for this code
QString s;
i cant use cin>>s
cout<<s
how to convert one no to string or string to corresponding integer.....................
i am really confused

i have a code
int a;
string b,c;
cin>>a>>b>>c
QSqlQuery q;
q.exec("insert into student values("+a+","+b+","+c")");
it was giving error of some type
i suppose it was due to wrong types
what is the solution to my problem please help ??

squidge
15th March 2011, 17:41
Either use Qt or use stdlib, it's best not to use both unless it's needed.

Eg:



#include <QDebug>

QString s = "foo";
qDebug() << s;


(as qDebug knows how to handle QStrings, but cout doesn't)

fober
15th March 2011, 17:44
try QString::toStdString() to get a std::string

Rhayader
16th March 2011, 00:34
As for number to QString it is QString::number(num) basically.
Check http://doc.qt.nokia.com/4.7-snapshot/qstring.html#number (http://doc.qt.nokia.com/4.7-snapshot/qstring.html#number)