Results 1 to 4 of 4

Thread: Conversion of int to char insertion into a qString

  1. #1

    Default Conversion of int to char insertion into a qString

    Hello,

    I have this..

    (hpos is an integer)

    senddata = ("#MS"+ (QByteArray::number(hpos)) +"$");

    This works well and sends..'#MS65$' for example. (if hpos=65)

    My problem is I do not want to send a string with the encoded deimal value, I need to convert hpos into the ascii char of value hpos..(ie. 'A' in this case) and insert in the string.

    Everything between the #MS and the $ will consist of many successive 8 bit values (data) for a uP.

    I know this is simple and will kick myself.. Tin hat on..

    Iain

  2. #2
    Join Date
    Apr 2011
    Posts
    195
    Thanks
    49
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Conversion of int to char insertion into a qString

    Take a look at QChar. I think theres one constructor, which takes an unsigned int as parameter(code).
    Qt Code:
    1. QChar(uint code)
    To copy to clipboard, switch view to plain text mode 

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

    Qtonimo (2nd April 2019)

  4. #3

    Default Re: Conversion of int to char insertion into a qString

    OK, thanks for your input.

    Still plugging away but no luck yet, sure its a simple solution.

  5. #4

    Default SOLVED: Conversion of int to char insertion into a qString

    OK, Im sure theres a more elegant way but its solved by creating a ByteArray of one element and inserting that into the QString.
    Implicit conversion

Similar Threads

  1. Replies: 6
    Last Post: 9th April 2014, 20:19
  2. Replies: 5
    Last Post: 8th September 2011, 10:38
  3. int to char conversion
    By cooper in forum Newbie
    Replies: 3
    Last Post: 14th June 2011, 03:50
  4. Char* <-> QString implicit conversion
    By kingfinn in forum Qt Programming
    Replies: 3
    Last Post: 15th March 2010, 08:26
  5. char* to QString: conversion
    By abghosh in forum Qt Programming
    Replies: 9
    Last Post: 8th March 2010, 09:32

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.