Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-42817

Google Suggest Example does not work anymore

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.5.0
    • 5.3.2, 5.4.0 Beta, 5.4.0 RC
    • Examples and Demos
    • None
    • Windows 7 64bits
    • 3e6a14168bfa1a8815baf28eba8eeff5e3a97a80

    Description

      The Google Suggest example doesn't work anymore, I thinkt it has nothing to do with the Qt 5.4 versions but to the XML return by google.

      The code example is based on two informations "suggestion" and "num_queries" but obviously the webservice provides by Google and use in the example doesn't give the "num_queries" anymore :

      http://google.com/complete/search?output=toolbar&q=test

      void GSuggestCompletion::handleNetworkData(QNetworkReply *networkReply)
      {
          QUrl url = networkReply->url();
          if (!networkReply->error()) {
              QStringList choices;
              QStringList hits;
      
              QByteArray response(networkReply->readAll());
              QXmlStreamReader xml(response);
              while (!xml.atEnd()) {
                  xml.readNext();
                  if (xml.tokenType() == QXmlStreamReader::StartElement)
                      if (xml.name() == "suggestion") {
                          QStringRef str = xml.attributes().value("data");
                          choices << str.toString();
                      }
                  if (xml.tokenType() == QXmlStreamReader::StartElement)
                      if (xml.name() == "num_queries") {
                          QStringRef str = xml.attributes().value("int");
                          hits << str.toString();
                      }
              }
      
              showCompletion(choices, hits);
          }
      
          networkReply->deleteLater();
      }
      

      The code rely on the fact that both lists have the same number of elements, it's not true so no completer is displayed :

      void GSuggestCompletion::showCompletion(const QStringList &choices, const QStringList &hits)
      {
      
          if (choices.isEmpty() || choices.count() != hits.count())
              return;
      }
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            veshivas Venugopal Shivashankar
            johnlamericain Jonathan Courtois
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes