Results 1 to 2 of 2

Thread: Using ANSI string type

  1. #1
    Join Date
    Jun 2009
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Using ANSI string type

    I am developing a class for use in under Qt that wants to have public members for converting to and from the ANSI string class. I have

    #include <string>
    class myClass {

    ...

    public:
    string & toString();
    void fromString(string & s);
    ...

    };


    The VC7 .NET 2003 compiler says: error 2061: syntax error: identifier string

    Is there something about compiling in the Qt env that makes the ANSI type, "string", inaccessible? If so, why does the compiler accept the #include? Is there a Qt type I should use instead?

    K.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Using ANSI string type

    It's nothing Qt related. string class is in std namespace, so either place an "using namespace std;" statement somewhere near the beginning of the file or replace all occurences of "string" with "std::string".

    Just before you do that, think if that's really what you want - Qt has methods for converting to/from std::string (QString::fromStdString() and QString::toStdString()) so possibly a better approach could be to equip your class with methods that operate using QString and if you need an std string, just use the conversion methods from QString. This would let your class blend better into Qt (if that something you consider worth the trouble).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. error compiling for QtCppIntegration
    By mzeal in forum Qwt
    Replies: 1
    Last Post: 5th January 2012, 08:25
  2. 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
  3. Compile 4.4.0
    By LordQt in forum Installation and Deployment
    Replies: 18
    Last Post: 29th May 2008, 13:43
  4. Replies: 6
    Last Post: 21st September 2007, 13:51
  5. dummy question(Error)
    By Masih in forum Qt Programming
    Replies: 12
    Last Post: 19th July 2007, 23:38

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.