Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Google Translator with Qt5
Forum Updated to NodeBB v4.3 + New Features

Google Translator with Qt5

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 3.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • freddy311082F Offline
    freddy311082F Offline
    freddy311082
    wrote on last edited by
    #1

    Hi... I need to make an application who let me call google translator with the string to translate... I have one example using qt4 (http://developer.nokia.com/Community/Wiki/Qt_Google_Translator), and all the things that I have found are coded with qt4...

    in qt5, all QHttp classes were removed and for that reason, this example dosen't work for me....

    what Am I suppose to do to solve my problem?

    somebody help me, please

    best regards

    Freddy

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      Hi,

      Use "QNetworkAccessManager":http://qt-project.org/doc/qt-5.1/qtnetwork/qnetworkaccessmanager.html for HTTP requests

      Create a QNetworkRequest, and then pass it to QNetworkAccessManager::get()

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • freddy311082F Offline
        freddy311082F Offline
        freddy311082
        wrote on last edited by
        #3

        I did it but it dosen't work... this is my code

        @
        #include <QApplication>
        #include <QNetworkAccessManager>
        #include <QUrl>
        #include <QNetworkReply>
        #include <iostream>

        int main(int argc, char argv[])
        {
        QApplication a(argc, argv);
        QNetworkAccessManager
        qnam = new QNetworkAccessManager();
        QNetworkReply* rep = qnam->get(QNetworkRequest(QUrl("https://translate.google.com/?hl=es-419&tab=TT#en/es/correr")));
        QString result = QVariant(rep->readAll()).toString();
        std::cout << result.toStdString();
        qnam->deleteLater();
        return a.exec();
        }
        @

        1 Reply Last reply
        0
        • JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          Hi,

          Qt is an event-driven framework. get() returns immediately without waiting for the download to finished, so that your program can do other things while downloading (think of large downloads). You need to wait for QNetworkAccessManager or QNetworkReply to emit the finished() signal before you call readAll(). Nokia's QHttp example was the same.

          Connect the finished() signal to a slot that reads the QNetworkReply.

          Some other things:

          To keep things simple, use HTTP instead of HTTPS for now. If you want to use HTTPS, you need to install OpenSSL.

          You don't have to convert the result of readAll() from QByteArray to QVariant. You can convert it directly to QString.

          You can use qDebug() instead of std::cout.

          According to the QNetworkAccessManager documentation, you are responsible for deleting the QNetworkReply when you finish extracting data from it.

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved