Results 1 to 13 of 13

Thread: Need help on 'google translator' code

  1. #1
    Join Date
    Dec 2008
    Location
    My spaceship needs repairs..so, I am stuck on beautiful earth
    Posts
    98
    Thanks
    25
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Smile Need help on 'google translator' code

    (am using Qt/Linux fedora 8)
    Hi,
    I found this great application in qt-apps.org on translating languages using google translator.
    I tried running it in my system but it didn't show me the translated text(though it worked for many of the others who used it).
    Also,I couldn't understand the necessity of a portion of the code specially in the received ("done()" slot ,regarding the slashes(///) and the ']' )so,I modified the code a bit to see if it would work without that section...well,the modified code isn't showing anything either.[ I used a couple of Message boxes to give me the values,in the 'request id' it pops up a message box twice showing '0' and in the done slot(),the Message box shows a blank]
    So,would anyone please test out the applications and tell me if they are showing any result in your system?I am giving the link to the original(exceeds size limit even after i zip it up)and am attaching the modified version,please check out both and in case the original works but not the modified one,I would appreciate it, if you could point out what I am doing wrong and where.
    Thanks in advance for any help.
    The link to the original application is :
    http://www.qt-apps.org/content/show....content=100039
    Attached Files Attached Files
    Last edited by rishiraj; 6th March 2009 at 12:11.
    If everything seems to be going well, you have obviously overlooked something.

  2. #2
    Join Date
    Dec 2008
    Location
    My spaceship needs repairs..so, I am stuck on beautiful earth
    Posts
    98
    Thanks
    25
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Post google translator code

    Hi everyone,
    No replies yet,so, thought I would raise my query again.
    Is the code below correct?It needs to send data to google translate and then set the retrieved translated text to a text edit box.It's not showing anything my side but,I was told that it might also be due to settings issues my side.So,I need someone to go over the code and tell me if it's ok.Please check the first post to get a better idea.
    Thanks.
    Qt Code:
    1. /*Sending the text which needs to be translated*/
    2. void myQtApp::translate()
    3. {
    4. QString from, to, text;
    5. from = langs->at(langfrom->currentIndex() );
    6. to = langs->at( langto->currentIndex() );
    7. text =text_from->toPlainText();
    8.  
    9. QByteArray ba("text=");
    10. ba.append( text.toUtf8() );
    11. QMessageBox::information(NULL,"outgoing data",QString(ba));
    12.  
    13. QString url=QString("http://translate.google.com/translate_a/t?Client=t&sl=" + from + "&tl=" +to);
    14. QMessageBox::information(NULL,"url",url);
    15.  
    16. http->setHost("www.google.com");
    17. http->post(url,ba);
    18. }
    19. /*The translated text is set in the 'to' text edit box.*/
    20. void myQtApp::done()
    21. {
    22. QMessageBox::information(NULL,"reached","entered done loop");
    23. QString transtext;
    24. ba1=http->readAll();
    25. QString text1;
    26. transtext=text1.fromUtf8(ba1);
    27. QMessageBox::information(NULL,"received",transtext);
    28. text_to->setText(transtext);
    29. }
    30. /*When the data is sent to google,the requestStarted(int) signal is generated which calls this slot*/
    31. void myQtApp::started()
    32. {
    33. int id1=http->currentId();
    34. QMessageBox::information(NULL,"process no.",QString(id1));
    35. }
    To copy to clipboard, switch view to plain text mode 
    If everything seems to be going well, you have obviously overlooked something.

  3. #3
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Need help on 'google translator' code

    take a look at this article. maybe it will help you.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  4. #4
    Join Date
    Dec 2008
    Location
    My spaceship needs repairs..so, I am stuck on beautiful earth
    Posts
    98
    Thanks
    25
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Need help on 'google translator' code

    Hi Spirt,
    thanks for the reply.
    I did check the page you mentioned.Alex had put the google translate application in qtapps.org.I downloaded it but, it didn't work in my system and he said that it might be due to some problem with Qhttp etc.I modified some of the commands in the code and removed some segfments which I didn't understand properly and tried running the modified version but ,it's not showing anything either.So,if anyone would go over the code and tell me if it looks ok and should work,I can conclude that it's a problem with my system and not the code(the original one by Alex worked for others so,I think it works properly)I need someone to test out the modified one and tell me if it shows any output.
    If everything seems to be going well, you have obviously overlooked something.

  5. #5
    Join Date
    Dec 2008
    Location
    My spaceship needs repairs..so, I am stuck on beautiful earth
    Posts
    98
    Thanks
    25
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default

    sorry,message got posted twice....pls check the above post.
    If everything seems to be going well, you have obviously overlooked something.

  6. #6
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Need help on 'google translator' code

    Alex's code works fine for me.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  7. #7
    Join Date
    Dec 2008
    Location
    My spaceship needs repairs..so, I am stuck on beautiful earth
    Posts
    98
    Thanks
    25
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Need help on 'google translator' code

    what about the modified one?does it show anything? ( i doubt it will,but,better to make sure
    If everything seems to be going well, you have obviously overlooked something.

  8. #8
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Need help on 'google translator' code

    seems like your example doesn't work, see attach.
    PS. file has been packed using 7z.
    Attached Files Attached Files
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  9. The following user says thank you to spirit for this useful post:

    rishiraj (9th March 2009)

  10. #9
    Join Date
    Dec 2008
    Location
    My spaceship needs repairs..so, I am stuck on beautiful earth
    Posts
    98
    Thanks
    25
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Need help on 'google translator' code

    Thanks for the info Spirit.
    If everything seems to be going well, you have obviously overlooked something.

  11. #10
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Need help on 'google translator' code

    try to change this line
    Qt Code:
    1. QString url=QString("http://translate.google.com/translate_a/t?Client=t&sl=" + from + "&tl=" +to);
    To copy to clipboard, switch view to plain text mode 
    om this one
    Qt Code:
    1. QString url=QString("/translate_a/t?client=t&sl=" + from + "&tl=" + to);
    To copy to clipboard, switch view to plain text mode 
    looks like this code works.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  12. #11
    Join Date
    Dec 2008
    Location
    My spaceship needs repairs..so, I am stuck on beautiful earth
    Posts
    98
    Thanks
    25
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Need help on 'google translator' code

    hi,
    did you mean that making the above changes in the modified code makes it work?
    Problem is none of the application shows anything my side....neither the original by Alex nor this modified one...so,I have to get the info from you.Thanks
    If everything seems to be going well, you have obviously overlooked something.

  13. #12
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Need help on 'google translator' code

    yes, if you applay changes (that I described abow) in your app version then it starts working.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  14. The following user says thank you to spirit for this useful post:

    rishiraj (9th March 2009)

  15. #13
    Join Date
    Dec 2008
    Location
    My spaceship needs repairs..so, I am stuck on beautiful earth
    Posts
    98
    Thanks
    25
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Need help on 'google translator' code

    Hi Spirit,
    Thank you so much for taking the time to go over the code and for rectifying the mistakes.
    If everything seems to be going well, you have obviously overlooked something.

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.