Results 1 to 4 of 4

Thread: Conversion to QString from int or byte return wrong val...

  1. #1
    Join Date
    Apr 2017
    Posts
    10
    Thanks
    3
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Conversion to QString from int or byte return wrong val...

    Qt Code:
    1. textedit->insertPlainText(QString.setNum(intArray[i]));
    To copy to clipboard, switch view to plain text mode 
    or
    Qt Code:
    1. textedit->insertPlainText(QString.number(intArray[i]));
    To copy to clipboard, switch view to plain text mode 
    same with byte array do great work but in case int = 200 i.e.
    it print -56

    what is wrong with me?????????????

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Conversion to QString from int or byte return wrong val...

    This should not even compile if it is supposed to be C++... ?!

    Try:
    Qt Code:
    1. QString strNum;
    2. textedit->insertPlainText(strNum.setNum(intArray[i]));
    To copy to clipboard, switch view to plain text mode 

    But before you go further I strongly suggest you first learn the C/C++ syntax.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Apr 2017
    Posts
    10
    Thanks
    3
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Conversion to QString from int or byte return wrong val...

    yy thank you for sugalksdjal;ksjd;lkjasdf
    about setNum true, but in case I've compiled that func, i guess compiller worn about it, or not?
    any way i used char array not int... my example work fine,.
    Thanks for your help...

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Conversion to QString from int or byte return wrong val...

    Quote Originally Posted by FalloutST View Post
    any way i used char array not int... my example work fine.
    char is a signed type with int range <-127,127> not <0,255>.

Similar Threads

  1. Casting Byte to QChar or QString
    By Habie in forum Qt Programming
    Replies: 1
    Last Post: 16th December 2015, 21:27
  2. Replies: 3
    Last Post: 19th April 2010, 15:16
  3. Replies: 4
    Last Post: 1st February 2010, 15:21
  4. Replies: 1
    Last Post: 17th January 2010, 08:36
  5. convert BYTE* to QString
    By tpf80 in forum Qt Programming
    Replies: 6
    Last Post: 8th April 2007, 11:29

Tags for this Thread

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.