Results 1 to 3 of 3

Thread: Problem in converting QString to QChar array?

  1. #1
    Join Date
    Mar 2007
    Posts
    30
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Problem in converting QString to QChar array?

    Before I used something like this:

    Say theString is a QString w.

    And I had this line of code:

    for(i=0; theString[i]!=QChar('\0'); i++)
    {
    if(theString[i]==QChar('('))
    {
    ... ...
    }
    }

    I ran the debug and found that altough i keeps on increasing from 0 to 1 to 2 and so on,

    The array under "theString" has only one entry "[0]" whose value is "46".

    I don't know how that happened, can someone help me?

    Also, I remember checked somewhere saying that if you transform a C styled string into

    QString, the QString won't be terminated by '\0'. I am concerning if my case is under this condition:

    My "theString" has gone through several transformations:

    First it is a QString, then it is strcpy ed to a char array, then this char array was passed as a parameter of function a, and the parameter requires a char*. After that, it is transferred from function a to function b, still as a parameter, but this time the parameter requires a QString. And then it is in function b that I want to convert this QString to QChar array.

    Without converting to QChar array, this QString seemed to work fine.

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem in converting QString to QChar array?

    Quote Originally Posted by KaKa View Post
    for(i=0; theString[i]!=QChar('\0'); i++)
    Better use:
    Qt Code:
    1. for( int i = 0; i < theString.size(); ++i) {
    2. ...
    3. }
    To copy to clipboard, switch view to plain text mode 

    Quote Originally Posted by KaKa View Post
    First it is a QString, then it is strcpy ed to a char array, then this char array was passed as a parameter of function a, and the parameter requires a char*. After that, it is transferred from function a to function b, still as a parameter, but this time the parameter requires a QString. And then it is in function b that I want to convert this QString to QChar array.
    What did you do exactly? QString is an Unicode string and you have to convert it to QByteArray using some 8-bit encoding before you can access the data as char *.

  3. The following user says thank you to jacek for this useful post:

    KaKa (19th March 2007)

  4. #3
    Join Date
    Mar 2007
    Posts
    30
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem in converting QString to QChar array?

    ok...I will try more on that ...Thanks!

Similar Threads

  1. Convert from iso-8859-1 to... Something else :-)
    By Nyphel in forum Qt Programming
    Replies: 4
    Last Post: 7th March 2007, 17:59
  2. QString problem
    By vermarajeev in forum Qt Programming
    Replies: 9
    Last Post: 26th October 2006, 19:10
  3. problem with array
    By mickey in forum General Programming
    Replies: 7
    Last Post: 16th May 2006, 15:39
  4. Converting QString to unsigned char
    By salston in forum Qt Programming
    Replies: 3
    Last Post: 24th April 2006, 22:10
  5. Problem with custom widget
    By jnana in forum Qt Programming
    Replies: 3
    Last Post: 15th March 2006, 11: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.