Results 1 to 4 of 4

Thread: unable to convert from one type to another

  1. #1
    Join Date
    Mar 2011
    Posts
    21
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default unable to convert from one type to another

    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 ??

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: unable to convert from one type to another

    Either use Qt or use stdlib, it's best not to use both unless it's needed.

    Eg:

    Qt Code:
    1. #include <QDebug>
    2.  
    3. QString s = "foo";
    4. qDebug() << s;
    To copy to clipboard, switch view to plain text mode 

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

  3. #3
    Join Date
    Jul 2010
    Posts
    17
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: unable to convert from one type to another

    try QString::toStdString() to get a std::string

  4. #4
    Join Date
    Aug 2009
    Location
    Greece
    Posts
    69
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: unable to convert from one type to another

    As for number to QString it is QString::number(num) basically.
    Check http://doc.qt.nokia.com/4.7-snapshot/qstring.html#number

Similar Threads

  1. Replies: 7
    Last Post: 19th April 2011, 12:20
  2. Replies: 1
    Last Post: 7th March 2010, 16:40
  3. Replies: 2
    Last Post: 22nd December 2009, 20:52
  4. Convert between a custom data type wrapped in a QVariant
    By darkadept in forum Qt Programming
    Replies: 2
    Last Post: 17th March 2009, 09:07
  5. Unable to define a new type with QVariant
    By max2g in forum Qt Programming
    Replies: 3
    Last Post: 23rd February 2008, 17:55

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.