Results 1 to 2 of 2

Thread: Something to do with character conversion, I just can not figure it out.

  1. #1
    Join Date
    Oct 2010
    Posts
    7
    Qt products
    Qt4

    Default Something to do with character conversion, I just can not figure it out.

    The program should accept the input, find to see if it is in the word, then replace the null character _ with the correct letter.

    char Guess[15];
    guess looks like this, depending on word size

    _ _ _ _ _

    Qt Code:
    1. void hangman::guessed()
    2. {
    3. char Letter;
    4. int Correct=0;
    5. QString tochar;
    6.  
    7. tochar = ui->lineEdit->text();
    8.  
    9. QByteArray foo = tochar.toLatin1();
    10.  
    11. char *letter = foo.data();
    12.  
    13.  
    14. Letter = *letter;
    15.  
    16.  
    17. // Loop through the word
    18. for(Subscript = 0; Subscript < Size; Subscript++)
    19. {
    20.  
    21. //if the guess is good tell the user and update Guess
    22. if(copy.at(Subscript) == Letter)
    23.  
    24.  
    25. {
    26.  
    27. Guess[Subscript] = Letter;
    28. Correct = 1;
    29. ui->textBox->append(Guess);
    To copy to clipboard, switch view to plain text mode 

    instead of proper output like, _ _ e _ _
    the textbox gets this appended to it.

    ð*º
    ð*º
    e*º
    ð*º`è_ ¸Ñ¦ ««««««««îþîþ

    I feel as though its clearly a failed data conversion, I just do not know what to attempt next.

  2. #2
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Something to do with character conversion, I just can not figure it out.

    Lots of pointer confusion occurring here. I don't understand why you're using pointers in the first place; the conversions between Qt string/character objects and C-style strings is certainly part of what's causing your problem.

    You ought to be able to write this routine entirely with QStrings and the functionality they provide. It's never a good idea to convert back and forth between different data representations unless there's no other way to accomplish something.

Similar Threads

  1. Draw figure underneath other figure
    By Mnemonic in forum Qt Programming
    Replies: 0
    Last Post: 7th April 2010, 13:38
  2. figure out?
    By uygar in forum Qt Programming
    Replies: 3
    Last Post: 20th May 2009, 08:19
  3. Character by Character (Unicode?) File Reading
    By mclark in forum Qt Programming
    Replies: 4
    Last Post: 22nd April 2009, 15:28
  4. How to read QStringList character by character
    By iamjayanth in forum Qt Programming
    Replies: 4
    Last Post: 3rd April 2009, 11:25
  5. Put figure in a grid
    By dreamer in forum Qt Programming
    Replies: 4
    Last Post: 4th March 2008, 03:01

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.