qstrcpy problem

Here is my problem:

I'm trying to copy a character into a QString (using KDevelop) :

QString temp;
char String [1];

//code that changes the value of String[0]

qstrcpy (temp, String[0]);

However, i get compiling errors saying "Cannot convert QString to char*"
All I want is to copy a character into a QString, any help would be greatly apreciated.

thanks

Comments

  • : Here is my problem:
    :
    : I'm trying to copy a character into a QString (using KDevelop) :
    :
    : QString temp;
    : char String [1];
    :
    : //code that changes the value of String[0]
    :
    : qstrcpy (temp, String[0]);
    :
    : However, i get compiling errors saying "Cannot convert QString to char*"
    : All I want is to copy a character into a QString, any help would be greatly apreciated.
    :
    : thanks
    :


    check out the prototype for qstrcpy:
    [b]char * qstrcpy ( char * dst, const char * src )[/b]

    there is no implicit conversion from QString to char*, as it's unsafe; you only get an implicit conversion to const char*.

    so use temp=(char*)String, or better yet temp.insert(0,String[0]) - safer.
  • thanks for the reply abc,

    I ended up using a QChar, the copy is made without any problem.


    thanks again




    : : Here is my problem:
    : :
    : : I'm trying to copy a character into a QString (using KDevelop) :
    : :
    : : QString temp;
    : : char String [1];
    : :
    : : //code that changes the value of String[0]
    : :
    : : qstrcpy (temp, String[0]);
    : :
    : : However, i get compiling errors saying "Cannot convert QString to char*"
    : : All I want is to copy a character into a QString, any help would be greatly apreciated.
    : :
    : : thanks
    : :
    :
    :
    : check out the prototype for qstrcpy:
    : [b]char * qstrcpy ( char * dst, const char * src )[/b]
    :
    : there is no implicit conversion from QString to char*, as it's unsafe; you only get an implicit conversion to const char*.
    :
    : so use temp=(char*)String, or better yet temp.insert(0,String[0]) - safer.
    :
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories